ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

1048 - Super long sums... HELP
Posted by Nephtali Garrido 19 Jul 2005 01:51
I still have troubles with this program, please help me, i don´t found the error.

Here is my code

#include <iostream>
using namespace std;

unsigned long int m, c;
int *v, *v2;

int main()
{     cin>>m;
      v=new int[m+5];
      v2=new int[m+5];
      for(c=0;c<m;c++)
        cin>>v[c]>>v2[c];
      c=m-1;
      while(c>0)
      {  v[c]+=v2[c];
         if(v[c]>=10)
         { v[c-1]+=v[c]/10;
           v[c]%=10;
         }
         c--;
      }
      v[0]+=v2[0];
      for(c=0;c<m;c++)
       cout<<v[c];
      delete [] v;
      delete [] v2;
      return 0;
}

beforehand thanks...
I see you have MLE (+)
Posted by qwerty 19 Jul 2005 02:01
Of course you get Memory limit: You use 2 arrays, where each element int (4 bytes). If there are 1000000 digits, than You need 4000000 bytes, that grather than 1 MB. Try to think out any trick. Even use array of char, or ... Try to solve this easy problem yourself :)
Good Luck
Re: I see you have MLE (+)
Posted by Nephtali Garrido 19 Jul 2005 02:10
Thanks, i´m working in that, I just want to know the better way to do it.

Thanks qwerty, I still work !!
I see you can not to do it... (+)
Posted by qwerty 19 Jul 2005 02:33
Try to store in every ceil of your array not 1 but more digits, i.e. use not 10-based nubmers, but 1000000-based. Or think more carefully and think out algo without arrays.
Thats all.
And try to solve other, more simple problems. For example 1000(A+B), or 1068.
Good Luck.
Ok, I try first other programs...
Posted by Nephtali Garrido 20 Jul 2005 06:56
Ok, I´ll try first other programs...
Posted by Nephtali Garrido 20 Jul 2005 06:59
Ok, I´ll take your advice.

I will try other programs, because i have the idea but something is missing :p

Thanks a lot, I appreciate your help
If you want, I'll help you more. (+)
Posted by qwerty 20 Jul 2005 14:49
My e-mail: barssimfi@mail.ru
If you know russian, it is very good. I can help you, I can correct your codes and find some mistakes in this easy problems.