11403 - Binary Multiplication

All about problems in Volume 114. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

arsalan_mousavian
Experienced poster
Posts: 111
Joined: Mon Jan 09, 2006 6:19 pm
Location: Tehran, Iran
Contact:

11403 - Binary Multiplication

Post 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

Last edited by arsalan_mousavian on Tue Jan 22, 2008 11:54 pm, edited 2 times in total.
In being unlucky I have the record.
arsalan_mousavian
Experienced poster
Posts: 111
Joined: Mon Jan 09, 2006 6:19 pm
Location: Tehran, Iran
Contact:

Post 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.
In being unlucky I have the record.
greve
New poster
Posts: 27
Joined: Tue May 29, 2007 8:52 pm
Contact:

Post 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.
For help with problems, visit http://www.uvatoolkit.com/
arsalan_mousavian
Experienced poster
Posts: 111
Joined: Mon Jan 09, 2006 6:19 pm
Location: Tehran, Iran
Contact:

Post 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????
In being unlucky I have the record.
mpi
New poster
Posts: 46
Joined: Fri Nov 03, 2006 7:53 pm
Location: Madrid

Post 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!
sonyckson
New poster
Posts: 49
Joined: Tue Feb 06, 2007 9:29 pm
Location: Cordoba, Argentina

Post 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.
arsalan_mousavian
Experienced poster
Posts: 111
Joined: Mon Jan 09, 2006 6:19 pm
Location: Tehran, Iran
Contact:

Post 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.
In being unlucky I have the record.
ani_mitr86
New poster
Posts: 20
Joined: Mon May 28, 2007 4:36 pm
Location: India

Post by ani_mitr86 »

hello

I don't understand why i keep getting TLE

can somebody help

here is my code

Code: Select all

//removed
Last edited by ani_mitr86 on Wed Jan 23, 2008 5:17 pm, edited 1 time in total.
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

There is a clarification for this problem:
http://online-judge.uva.es/board/viewtopic.php?t=27828

-----
Rio
ani_mitr86
New poster
Posts: 20
Joined: Mon May 28, 2007 4:36 pm
Location: India

Post by ani_mitr86 »

thanks...

But this is pathetic that something given in problem description is wrong
mpi
New poster
Posts: 46
Joined: Fri Nov 03, 2006 7:53 pm
Location: Madrid

Post by mpi »

well, problem descriptions are written by humans, not by computers
SHAHADAT
New poster
Posts: 23
Joined: Thu Jun 22, 2006 8:55 am
Location: sust,bangladesh

Post 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.
-------------- ASHA TAR AKMATRO VHELA.
mysword
New poster
Posts: 26
Joined: Sun Mar 06, 2005 8:52 am

Post 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?????????!!!!!!!!!!!
Robert Gerbicz
Experienced poster
Posts: 196
Joined: Wed May 02, 2007 10:12 pm
Location: Hungary, Pest county, Halasztelek
Contact:

Post 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.
Ron
Learning poster
Posts: 55
Joined: Mon Jul 23, 2007 5:01 pm
Location: INDIA

Re: 11403 - Binary Multiplication

Post 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;
}

Post Reply

Return to “Volume 114 (11400-11499)”