shpvb's blog

By shpvb, history, 4 years ago, In English

[Edit: Issue resolved, the issue was regarding the bytes taken by size_t on different platforms]

Going through some blogs regarding the cause of the difference in output between judge and local terminal, I saw majorly the Out of Bound error. But I have looked across my code multiple times, not able to find the generation of such an exception.

Problem: 1335E1 - Three Blocks Palindrome (easy version). My submission: 79635901

For test case 1, the output is different,

Participant's output: 6 2 3 0 0 2

Output on the local machine: 7 2 4 1 1 3

I suspect the error may lie somewhere in the implementation of sets. Please help me through if anyone catches the issue. Cheers.

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

in my machine it gives 6 2 3 0 0 2 so may be problem with your compiler

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I checked on the Codechef online ide (Code, compile and run), the output is 7 2 4 1 1 3 there as well.

»
4 years ago, # |
  Vote: I like it +21 Vote: I do not like it

This is the offending line:

s.insert(mp(-1*pos[k].size(), k));

Although technically undefined behaviour, it will end up working on 64-bit platforms using major compilers. My guess is codeforces is a 32-bit platform where sizeof(size_t) == 4, so your line will end up inserting a huge number as the first element.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by shpvb (previous revision, new revision, compare).