Page 10 of 15

Posted: Fri Jun 22, 2007 5:22 pm
by Itachi-Forsaken
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

Posted: Fri Jun 22, 2007 8:06 pm
by Jan
The max size can be 1000000. So, you can't allocate such memory locally. Try to declare the arrays globally.

Hope it helps.

Posted: Sat Jun 23, 2007 1:41 am
by Itachi-Forsaken
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

Posted: Sat Jun 23, 2007 9:55 pm
by Jan
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.

Posted: Sun Jun 24, 2007 4:58 pm
by Itachi-Forsaken
Thank you so much it finally worked
But why does it make a difference whether it's a function or not?

Posted: Mon Jun 25, 2007 10:56 am
by Jan
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.

Posted: Thu Sep 20, 2007 12:44 pm
by rossi kamal
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;
}

Posted: Sun Oct 07, 2007 7:33 pm
by sapnil
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

Posted: Sun Oct 21, 2007 2:16 am
by sumankar
WR wrote:Your result is really

Code: Select all

...

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

Help me - Getting Wrong answer Super Long Sums

Posted: Tue Feb 05, 2008 4:53 pm
by Rajesh V
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;
}

10013 Wrong Answer

Posted: Mon Mar 31, 2008 6:29 am
by naffi

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.

Re: 10013 Wrong Answer

Posted: Tue Apr 01, 2008 9:00 pm
by Jan
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:

Re: why wa 10013 super long sums

Posted: Sun May 04, 2008 1:00 pm
by Obaida
What happened to this..!

Re: why wa 10013 super long sums

Posted: Sun May 04, 2008 1:28 pm
by Jan
Check the length of 'M'.

Re: 10013

Posted: Tue May 06, 2008 1:11 pm
by Obaida
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.