Page 11 of 15

Re: 10013 - Super Long Sums

Posted: Fri May 30, 2008 8:06 am
by sreejond
ac

Re: 10013 - Super Long Sums

Posted: Mon Jun 02, 2008 6:28 pm
by Jan
When you use' %c' you should be careful.

Code: Select all

scanf("%c%c%c",&a[k],&ch,&b[k]); should be replaced with
scanf(" %c %c %c",&a[k],&ch,&b[k]);
Hope it helps.

Re: 10013 - Super Long Sums

Posted: Tue Jun 03, 2008 8:07 pm
by sreejond
vhaia,
sorry for disturbing again.
when i use scanf(" %c %c %c",&a[k],&ch,&b[k]);
my program give no ans.

one question more why i use "%c" like this.
thank you for your reply.

sreejon
cuet'06

Re: 10013 - Super Long Sums

Posted: Tue Jun 03, 2008 8:36 pm
by Jan
The reason is scanf eliminates spaces. Thats why you shouldn't use %c for eliminating spaces.

TLE Help

Posted: Mon Aug 04, 2008 7:06 pm
by meteu336
Can anyone help with the following code? I've gotten TLE for all my submissions and I can't figure out how to optimize it more than where it is at. Thanks.

Code: Select all

#include <iostream>
#include <time.h>
#include <sstream>
#include <algorithm>
using namespace std;

int main() {	
	int cases = 0, digits = 0;
	ostringstream s;
	int v[1000010];
	
	//clock_t start, end;
	//start = clock();
	
	cin >> cases;
	
	while ( cases --> 0 ) {
		cin >> digits;

		int a, b;
		for ( int i = 0; i < digits; i++ ) {
			cin >> a >> b;
			v[i] = a + b;
		}
		
		ostringstream s2;
		for ( int i = digits - 1; i >= 0; i-- ) {
			if ( v[i] >= 10 ) {
				v[i - 1]++;
				v[i] -= 10;
			}
			
			s2 << v[i];
		}
		
		string s2_rev = s2.str();
		reverse(s2_rev.begin(), s2_rev.end());
		s << s2_rev << endl;
	
		if ( cases >= 1 ) s << endl;
	}
	cout << s.str();
	
	//end = clock();
	//printf ("%f seconds\n", ((float)end - (float)start) / 1000000.0F);

	return 0;
}

10013 - Super Long Sums - WA

Posted: Mon Nov 10, 2008 2:57 pm
by RoMeLuKo
Hi, i got WA, and I don't know why, please, help me to debug it, where the code fails? :) ... thanks :roll:

Code: Select all

Removed After AC
Yes!, problem was "\n\n" to end.

Thanks! :D

Re: 10013 - Super Long Sums

Posted: Wed Dec 17, 2008 10:55 am
by abid_iut
why I am getting WA
I have passed all the test cases given in the boards
please some one check and tell me why WA
here is my code:

Code: Select all

Removed After AC
pls help :(

Re: 10013 - Super Long Sums

Posted: Wed Dec 17, 2008 7:05 pm
by Articuno
Your code is not AC because of this:

Code: Select all

printf("\n\n");
The problem description says:
There is a blank line between output blocks.
Good luck

Re: 10013 - Super Long Sums

Posted: Wed Dec 17, 2008 11:47 pm
by abid_iut
Thanks Articuno
Got AC!! :)

Re: 10013 - Super Long Sums

Posted: Thu Jan 01, 2009 10:07 pm
by sazzadcsedu
whats wrong with my code!!!
got WA.

Code: Select all

  
                #include<stdio.h>
                #include<memory.h>   
 
                     int sum[1000002];


                          int main()

 
					   {


						         int i,ndigit,a,b,ncount;
						   
                            int c,count=1;
                               
                          scanf("%d",&ncount);
						 


						  while(count<=ncount)
						  {
                         
                          memset(sum,0,sizeof(sum));

                          scanf("\n\n%d",&ndigit);


						  for(i=0;i<ndigit;i++)

						  {

                            scanf("\n%d %d",&a,&b);

						     c=0;

                            sum[i]=a+b;
		

						  }


                          
						  for(i=ndigit-1;i>0;i--)

						  {
                              
							  sum[i]=sum[i]+c;
							  if(sum[i]>=10){

                                 c=1;
							     sum[i]=sum[i]%10;
							  }

                              else
								  c=0;
                          } 

						    sum[i]=sum[i]+c;
			
						   
						   for(i=0;i<ndigit;i++)

						   { 
							  printf("%d",sum[i]);
							  
						   }

						   
						   if(count<ncount)
						    printf("\n\n");

						 

						   count++;

                       
						   
                       }
                          
						  return 0;
                      } 

   

Re: 10013 - Super Long Sums

Posted: Fri Jan 02, 2009 3:01 pm
by abid_iut
change this part

Code: Select all

                     if(count<ncount)
                      printf("\n\n");
into this

Code: Select all

                     if(count<ncount)
                      printf("\n\n");
                     else printf("\n");
hope it helps

Re: 10013 - Super Long Sums

Posted: Sun Jan 11, 2009 8:45 am
by choby123
Hi this is my code, can anybody tell me why is that i'm getting TLE please :(

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
long long cant;
char aux[10];

cin>>cant;

for(int i=0; i<cant; i++)
{
if(i>0) cout<<endl;
gets(aux);
int pares;
cin>>pares;
int num1, num2;
vector<int> resp;
for(int j=0; j<pares; j++)
{
cin>>num1>>num2;
resp.push_back(num1+num2);
}
reverse(resp.begin(),resp.end());
for(int j=0; j<(resp.size()-1); j++)
{
if(resp[j]>=10)
{
resp[j+1]+=1;
resp[j]%=10;
}
}

if(resp[resp.size()-1]>=10)
{

resp[resp.size()-1]=resp[resp.size()-1]%10;
resp.push_back(1);
}

reverse(resp.begin(),resp.end());
for(int j=0; j<resp.size(); j++)
cout<<resp[j];
cout<<endl;


}
return 0;
}

Re: 10013 - Super Long Sums

Posted: Thu Jan 15, 2009 11:46 am
by linux
choby123 wrote:Hi this is my code, can anybody tell me why is that i'm getting TLE please :(

Code: Select all

gets(aux);
This is not necessary. Leave it to cin.

Code: Select all

vector<int> resp;
Input range is huge. I got AC with array size of 1000000. So, vector isn't fast enough data structure for this problem. Use static array.

Code: Select all

if(resp[resp.size()-1]>=10)
{

resp[resp.size()-1]=resp[resp.size()-1]%10;
resp.push_back(1);
}
This case is also not necessary.

Re: 10013 - Super Long Sums

Posted: Tue Mar 31, 2009 2:59 am
by philipmichel
Hey guys, I think I need some help here...
I don't think this problem is hard or anything, but i'm having a hell of a time to get AC here.
This is my code anyways:

Code: Select all

#include <iostream>
#include <cstdlib>//10013
using namespace std;
unsigned long nums[2][1000001],n,m,carry=0;
int main()
{
	cin>>n;for(int i=0;i<n;++i){cin>>m;memset(nums,0,sizeof(int)*2*1000001);
	for(int j=m-1;j>=0;--j)cin>>nums[0][j]>>nums[1][j];carry=0;
	for(int j=0;j<m;++j){nums[0][j]+=nums[1][j]+carry;carry = nums[0][j]/10;nums[0][j]%=10;if(carry && j==m-1)++m;}
	if(i)cout<<endl;for(int j=m-1;j>=0;--j)cout<<nums[0][j];cout<<endl;}
	return 0;
}
I just keep getting TLE no matter what I do =/

heres my input file:

6

18
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9

3
3 0
7 9
2 8


5
5 0
8 1
8 0
1 1
1 1

4
8 0
6 3
6 3
2 8

3
1 5
3 6
2 0

4
0 9
0 9
0 9
1 9

And heres the output:
1999999999999999998

470

59822

9000

692

10000

Now tnx in advance for any help =D!

Re: 10013 - Super Long Sums

Posted: Mon Apr 06, 2009 11:58 pm
by aliahmed
Getting Runtime Error.....
Can anyone help me

Got AC. Thanks Obaida