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

Itachi-Forsaken
New poster
Posts: 10
Joined: Mon May 07, 2007 4:45 am

Post by Itachi-Forsaken » Fri Jun 22, 2007 5:22 pm

Hi I've been getting Runtime Error (Signal 11) for this problem I was wondering if anyone can tell me what's wrong with my code plz

Code: Select all

removed
Last edited by Itachi-Forsaken on Mon Jun 25, 2007 11:16 pm, edited 1 time in total.

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

Post by Jan » Fri Jun 22, 2007 8:06 pm

The max size can be 1000000. So, you can't allocate such memory locally. Try to declare the arrays globally.

Hope it helps.
Ami ekhono shopno dekhi...
HomePage

Itachi-Forsaken
New poster
Posts: 10
Joined: Mon May 07, 2007 4:45 am

Post by Itachi-Forsaken » Sat Jun 23, 2007 1:41 am

I changed it into a global variable, but I still get the same error
I wonder if there is another mistake?
Here is my new code:

Code: Select all

removed
Last edited by Itachi-Forsaken on Mon Jun 25, 2007 11:15 pm, edited 1 time in total.

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

Post by Jan » Sat Jun 23, 2007 9:55 pm

Remove the 'increase' function. Replace the following part...

Code: Select all

              if( num1[i]>9 ) 
              {    
                  num1[i]-=10; 
                  i=increase(i+1); 
              }
with

Code: Select all

              while( num1[i]>9 ) 
              {    
                  num1[i]-=10; 
                  num1[i+1]++;
                  i++;
              }
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

Itachi-Forsaken
New poster
Posts: 10
Joined: Mon May 07, 2007 4:45 am

Post by Itachi-Forsaken » Sun Jun 24, 2007 4:58 pm

Thank you so much it finally worked
But why does it make a difference whether it's a function or not?

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

Post by Jan » Mon Jun 25, 2007 10:56 am

In worst case you have to call the recursive function million times. Which can make system-stack overflow. Probably this could be the reason.

P.S. Don't forget to remove your codes.
Ami ekhono shopno dekhi...
HomePage

rossi kamal
New poster
Posts: 14
Joined: Mon Sep 03, 2007 10:11 am
Contact:

Post by rossi kamal » Thu Sep 20, 2007 12:44 pm

i dont understand why i am getting wrong answer

Code: Select all


#include<stdio.h>

//10013

int main()
{
	
	
	
	
	//freopen("in10013.txt","r",stdin);
	
	int i,n;
	scanf("%d",&n);
    

	for(i=1;i<=n;i++)
	{
	    
		
		long num[100][2],sum[100];
		long  ad=0;
		long  j,m;
        int f=1;
		
		scanf("%ld",&m);
		
		for(j=1;j<=m;j++)
			scanf("%ld %ld",&num[j][0],&num[j][1]);
       
		for(j=0;j<=m;j++)
		  sum[j]=0;


		for(j=m;j>=1;j--)  
		{ 
			f=1;
			sum[j]+=num[j][0]+num[j][1];
		    if(sum[j]/10>0)
			{	
				sum[j-1]=sum[j]/10;
			    sum[j]=sum[j]%10;
				f=0;	
			
			}

			
		    
		
		}	
		
		for(j=0+f;j<=m;j++)
			printf("%ld",sum[j]);
       
		printf("\n");
	    printf("\n");	
		


	
	
	}








	return 0;
}

sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:

Post by sapnil » Sun Oct 07, 2007 7:33 pm

to rossi kamal

*** The array size is 1000000
*** print blank line between two tast case
*** all data type is long
*** Declare data out of for loop

Thanks
keep posting
Sapnil

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Post by sumankar » Sun Oct 21, 2007 2:16 am

WR wrote:Your result is really

Code: Select all

...

6692                 < ---- ????
?
What is wrong with this answer?

Rajesh V
New poster
Posts: 2
Joined: Mon Jan 14, 2008 11:25 am

Help me - Getting Wrong answer Super Long Sums

Post by Rajesh V » Tue Feb 05, 2008 4:53 pm

I am getting right answers for the test cases given. But I am tired with the WAs given by the judge. Please help me and thanks in advance.

Code: Select all

#include<iostream>
#include<string>
#include<map>
#include<vector>
using namespace std;
 char a[1000001] = {'\0'}, b[1000001] = {'\0'}, c[1000001] = { '\0' };

int main()
{
    int n;
    cin >> n;
    while( n-- )
    {
	int x;	
	cin >> x;
	
	 int sum , carry = 0;
	 carry = 0;
	 sum = 0;
		
	for( int i = x - 1; i >= 0; i-- )
	{	
            cin >> a[i] >> b[i];
        }
	for( int i = 0; i < x; i++ )
	{
            sum = ( a[i] - '0' ) + ( b[i]  - '0' ) + carry;
	    c[i] = ( sum % 10 ) + '0';
	    if( sum > 9 )
		carry = 1;
	    else
		carry = 0;
	}
	//if( carry == 1 )
	//cout << carry;
	for( int i = x - 1; i >= 0; i-- )
	    cout << c[i];
	if( n > 0 )
	    cout << endl << endl ;
	
    }
    return 0;
}

naffi
New poster
Posts: 23
Joined: Wed Mar 19, 2008 12:25 pm
Location: BUET, Bangladesh
Contact:

10013 Wrong Answer

Post by naffi » Mon Mar 31, 2008 6:29 am

Code: Select all

#include<iostream>
#include<math.h>

using namespace std;

main()
{
#ifndef ONLINE_JUDGE
	freopen("input","r",stdin);	
	freopen("output","w",stdout);
#endif
	unsigned long N,M,n1,n2;
	int x,y,z;
	scanf("%lu\n\n",&N);
	while(N--)
	{
		scanf("%lu\n",&M);
		n1 = 0;
		n2 = 0;
		while(--M)
		{
			scanf("%d %d\n",&y,&z);
			n1 = (n1 + y)*10;
			n2 = (n2 + z)*10;
		}
		scanf("%d %d\n",&y,&z);
		n1 = n1 + y;
		n2 = n2 + z;
		printf("%lu\n",n1+n2);
		if(N != 0)
		{
			cout<<endl;
			scanf("\n");
		}
	}
}

can anyone tell me where is the wrong.I tested many sample I/O.

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

Re: 10013 Wrong Answer

Post by Jan » Tue Apr 01, 2008 9:00 pm

naffi wrote:can anyone tell me where is the wrong.I tested many sample I/O.
Can you tell me why this should be right? Just read the question again. M can be very large. Just make a test case where M = 20, and then check the result yourself. Hope it helps. :wink:
Ami ekhono shopno dekhi...
HomePage

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: why wa 10013 super long sums

Post by Obaida » Sun May 04, 2008 1:00 pm

What happened to this..!
Last edited by Obaida on Tue May 06, 2008 1:10 pm, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

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

Re: why wa 10013 super long sums

Post by Jan » Sun May 04, 2008 1:28 pm

Check the length of 'M'.
Ami ekhono shopno dekhi...
HomePage

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10013

Post by Obaida » Tue May 06, 2008 1:11 pm

I am Acc.. Now But it took so much time 1.530
I used this method...

Code: Select all

9   8   7   6
5   3   7   5
---------------+
14  11  14  11

Step by step normalization
14  11  15   1
14  12   5   1
15   2   5   1

Result = 15251
Could someone show me more efficient way.
try_try_try_try_&&&_try@try.com
This may be the address of success.

Post Reply

Return to “Volume 100 (10000-10099)”