Блог пользователя JVirak

Автор JVirak, история, 9 лет назад, По-английски

So I've been working through the A2OJ Div 2C ladder. For question 12 http://mirror.codeforces.com/problemset/problem/490/C my code seems to be running fine on my computer (at least for the three test cases given as examples) but it fails on the first test case (exactly the same as the first example) when I try to actually submit it http://mirror.codeforces.com/contest/490/submission/24563289.

It seems that for some reason it isn't picking up the answer in the loop (again, it does on my local machine) and is getting through the loop (which stops when an answer is found) and outputting "NO". Any help appreciated.

  • Проголосовать: нравится
  • -18
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +6 Проголосовать: не нравится

There is array out of bound access it this line: A[i]=10*A[i]+(10*A[i-1]); when i == 0. This is undefined behaviour and probably it is the reason of different answers.

Try to change that line to something like this:

A[i]=10*A[i];
if (i > 0)
   A[i] += (10*A[i-1]);
»
9 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +1 Проголосовать: не нравится

see fixed solution. 24563693

fixed part of code:

   A[0] = (s[0]-'0') % a; // 1. --->see  %a 
    for (ll i=1;i<n;i++){  // 2. --->see i = 1
        A[i] = s[i]-'0';
        A[i] = A[i] + (10 * A[i-1]); //3. --->see removed 10*A[i].      //computes the prefixes mod a
        A[i]=A[i]%a;
    }
    ll k=1;
    B[n-1]= (s[n-1]-'0')%b; // 4. ---> see %b