10013 - Super long sums

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

Moderator: Board moderators

User avatar
sreejond
New poster
Posts: 32
Joined: Fri May 23, 2008 6:16 pm
Contact:

Re: 10013 - Super Long Sums

Post by sreejond » Fri May 30, 2008 8:06 am

ac
Last edited by sreejond on Thu Jun 04, 2009 2:40 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10013 - Super Long Sums

Post by Jan » Mon Jun 02, 2008 6:28 pm

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.
Ami ekhono shopno dekhi...
HomePage

User avatar
sreejond
New poster
Posts: 32
Joined: Fri May 23, 2008 6:16 pm
Contact:

Re: 10013 - Super Long Sums

Post by sreejond » Tue Jun 03, 2008 8:07 pm

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

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10013 - Super Long Sums

Post by Jan » Tue Jun 03, 2008 8:36 pm

The reason is scanf eliminates spaces. Thats why you shouldn't use %c for eliminating spaces.
Ami ekhono shopno dekhi...
HomePage

meteu336
New poster
Posts: 1
Joined: Mon Aug 04, 2008 6:48 pm

TLE Help

Post by meteu336 » Mon Aug 04, 2008 7:06 pm

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

User avatar
RoMeLuKo
New poster
Posts: 7
Joined: Mon Jan 02, 2006 1:44 am
Location: Puno - Peru
Contact:

10013 - Super Long Sums - WA

Post by RoMeLuKo » Mon Nov 10, 2008 2:57 pm

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
Last edited by RoMeLuKo on Sat Nov 07, 2009 2:30 am, edited 1 time in total.
Luck!

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10013 - Super Long Sums

Post by abid_iut » Wed Dec 17, 2008 10:55 am

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 :(
Last edited by abid_iut on Wed Dec 17, 2008 11:48 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

Articuno
Learning poster
Posts: 78
Joined: Sun Nov 30, 2008 5:00 pm
Location: IUT-OIC, Dhaka, Bangladesh

Re: 10013 - Super Long Sums

Post by Articuno » Wed Dec 17, 2008 7:05 pm

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
May be tomorrow is a better day............ :)

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10013 - Super Long Sums

Post by abid_iut » Wed Dec 17, 2008 11:47 pm

Thanks Articuno
Got AC!! :)
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 10013 - Super Long Sums

Post by sazzadcsedu » Thu Jan 01, 2009 10:07 pm

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

   
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10013 - Super Long Sums

Post by abid_iut » Fri Jan 02, 2009 3:01 pm

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
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

choby123
New poster
Posts: 1
Joined: Sun Jan 11, 2009 6:51 am

Re: 10013 - Super Long Sums

Post by choby123 » Sun Jan 11, 2009 8:45 am

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

User avatar
linux
Learning poster
Posts: 56
Joined: Sat Jul 01, 2006 12:21 pm
Location: CA-95054
Contact:

Re: 10013 - Super Long Sums

Post by linux » Thu Jan 15, 2009 11:46 am

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.
Solving for fun..

philipmichel
New poster
Posts: 1
Joined: Tue Mar 31, 2009 2:52 am

Re: 10013 - Super Long Sums

Post by philipmichel » Tue Mar 31, 2009 2:59 am

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!

aliahmed
New poster
Posts: 24
Joined: Fri Oct 24, 2008 8:37 pm
Location: CUET, Chittagong, Bangladesh
Contact:

Re: 10013 - Super Long Sums

Post by aliahmed » Mon Apr 06, 2009 11:58 pm

Getting Runtime Error.....
Can anyone help me

Got AC. Thanks Obaida
Last edited by aliahmed on Tue Apr 07, 2009 10:50 pm, edited 1 time in total.

Post Reply

Return to “Volume 100 (10000-10099)”