Page 1 of 2

11403 - Binary Multiplication

Posted: Tue Jan 22, 2008 11:19 pm
by arsalan_mousavian
I've got many WAs on this problem, would you please take a look at my code????

Code: Select all

// removed
input:

Code: Select all

101010111 101011
101 1
1 101
11111 1111
111111111111111111111111111111 111111111111111111111111111111
1 1
Output:

Code: Select all

     101010111
        101011
     ---------
     101010111
    101010111
   000000000
  101010111
 000000000
101010111
--------------
11100110011101

101
  1
---
101
---
101

  1
101
---
  1
 0
1
---
101

    11111
     1111
    -----
    11111
   11111
  11111
 11111
---------
111010001

                              111111111111111111111111111111
                              111111111111111111111111111111
                              ------------------------------
                              111111111111111111111111111111
                             111111111111111111111111111111
                            111111111111111111111111111111
                           111111111111111111111111111111
                          111111111111111111111111111111
                         111111111111111111111111111111
                        111111111111111111111111111111
                       111111111111111111111111111111
                      111111111111111111111111111111
                     111111111111111111111111111111
                    111111111111111111111111111111
                   111111111111111111111111111111
                  111111111111111111111111111111
                 111111111111111111111111111111
                111111111111111111111111111111
               111111111111111111111111111111
              111111111111111111111111111111
             111111111111111111111111111111
            111111111111111111111111111111
           111111111111111111111111111111
          111111111111111111111111111111
         111111111111111111111111111111
        111111111111111111111111111111
       111111111111111111111111111111
      111111111111111111111111111111
     111111111111111111111111111111
    111111111111111111111111111111
   111111111111111111111111111111
  111111111111111111111111111111
 111111111111111111111111111111
------------------------------------------------------------
111111111111111111111111111110000000000000000000000000000001

1
1
-
1
-
1


Posted: Tue Jan 22, 2008 11:23 pm
by arsalan_mousavian
These are 3 clarifications about this problem, sent during the real contest:
1.The last line with a couple of 0s are missing from the input file. The input terminates with EOF.
2.No binary number in the input file will be equal to 0 or have leading 0.
3.There's an empty line after each test case.

Posted: Tue Jan 22, 2008 11:42 pm
by greve
Your code gets AC if you print a new line after each test case (also do not print a newline before the first test case as you do now). Furthermore you should not print blanks after the digits.

Posted: Tue Jan 22, 2008 11:53 pm
by arsalan_mousavian
greve wrote:Your code gets AC if you print a new line after each test case (also do not print a newline before the first test case as you do now). Furthermore you should not print blanks after the digits.
Thanks a lot, i got Acc, BTW i've found the trailing space bug before your post and i've submited and i got WA(but actually it was PE because i've just print one extra blank) , does the UVA new server judge detect presentation error????

Posted: Wed Jan 23, 2008 12:25 am
by mpi
:o I haven't seen this so far!
My program gets AC when I print a newline char after each test case, not between test cases. The statement of the problem is very clear:
Each result will be separated by an empty line
I got dozens of WAs the day of the contest!! :evil:
Anyway, I thought this would be PE, never WA. It's just an extra char!!!

P.S.: Thanks greve!

Posted: Wed Jan 23, 2008 3:20 am
by sonyckson
Well, i think many of us had the same problem. Someone can say that there was a clarification, but as it was written ( "There's an empty line after each test case." ), i misunderstood the clarification, and i thought that there was a line after each case in the input. Anyway, it was a nice contest. gl! Eric.

Posted: Wed Jan 23, 2008 9:53 am
by arsalan_mousavian
sonyckson wrote:Well, i think many of us had the same problem. Someone can say that there was a clarification, but as it was written ( "There's an empty line after each test case." ), i misunderstood the clarification, and i thought that there was a line after each case in the input. Anyway, it was a nice contest. gl! Eric.
That's exactly what i understood from the clarification when i read it.

Posted: Wed Jan 23, 2008 5:03 pm
by ani_mitr86
hello

I don't understand why i keep getting TLE

can somebody help

here is my code

Code: Select all

//removed

Posted: Wed Jan 23, 2008 5:11 pm
by rio
There is a clarification for this problem:
http://online-judge.uva.es/board/viewtopic.php?t=27828

-----
Rio

Posted: Wed Jan 23, 2008 5:16 pm
by ani_mitr86
thanks...

But this is pathetic that something given in problem description is wrong

Posted: Wed Jan 23, 2008 8:02 pm
by mpi
well, problem descriptions are written by humans, not by computers

Posted: Thu Feb 21, 2008 11:19 pm
by SHAHADAT
I got AC in this problem not checking termination case 0 0 but EOF.Can not the problem description or input file be corrected?
Sorry for my poor english.

Posted: Sat Mar 08, 2008 6:38 pm
by mysword
Why the problem settler or the uva site admin does not change the problem statement or the dataset? Who are wasting our time?????????!!!!!!!!!!!

Posted: Sat Mar 08, 2008 8:26 pm
by Robert Gerbicz
mysword wrote:Who are wasting our time?????????!!!!!!!!!!!
http://online-judge.uva.es/board/profil ... rofile&u=4

I'm not surprising on these things. Just one example: it's about 50 days spent since there are problems 114xy, but there is no Volume CXIV forum.

Re: 11403 - Binary Multiplication

Posted: Mon Aug 18, 2008 10:10 pm
by Ron
i'm getting WA.........
what is wrong in my code...............plzzzzz help....!!!!

Code: Select all

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

string binary_sum(string x,string y){
	int i,j,c=0,sum,l1=x.length(),l2=y.length();
	string s1,s2;
	if(l1>l2){
		j=l1;l1=l2;l2=j;
		s2=x;
		s1=y;
	}
	else{
		s2=y;
		s1=x;
	}
	for(i=l1-1,j=l2-1;i>=0;i--,j--){
		sum=(s1[i]-'0')+(s2[j]-'0')+c;
		if(sum<2){
			s2[j]=(char)(sum+'0');
			c=0;
		}
		else{
			c=1;
			s2[j]=(char)(sum%2+'0');
		}
	}
	while(j>=0&&c>0){
		sum=(s2[j]-'0')+c;
		if(sum<2){
			s2[j]=(char)(sum+'0');
			c=0;
		}
		else{
			c=1;
			s2[j]='0';
		}
		j--;
	}
	if(c>0)	s2=(char)('1')+s2;
	if(s2.length()==0)	return "0";
	return s2;
}

int main(){
	int i,j,k,l,m;
	string s1,s2,s;
	bool f=1;
	while(cin>>s1>>s2&&(s1[0]!='0'||s2[0]!='0')){
		if(f)	f=0;
		else	cout<<endl;
		vector<string> v;
		k=s1.length();
		l=s2.length();
		s=string(k,'0');
		string ans="0";
		for(i=l-1;i>=0;i--){
			if(s2[i]=='1'){
				v.push_back(s1);
				ans=binary_sum(ans,s1+string(l-i-1,'0'));
			}
			else{
				v.push_back(s);
			}
		}
		m=ans.length();
		j=v.size();
		cout<<string(m-k,' ')+s1<<endl;
		cout<<string(m-l,' ')+s2<<endl;
		s=string(max(l,k),'-');
		cout<<string(m-s.length(),' ')+s<<endl;
		for(i=0;i<j;i++){
			cout<<string(m-v[i].length()-i,' ')<<v[i]<<endl;
		}
		cout<<string(m,'-')<<endl<<ans<<endl;
	}
	return 0;
}