-Wave-'s blog

By -Wave-, 10 years ago, In English

I wrote a solution to 525E that works... just not on Codeforces. It produces correct output both on my machine and on Ideone, but prints something different on Codeforces.

Here is the submission: http://mirror.codeforces.com/contest/525/submission/11007405

And the Ideone test: http://ideone.com/IMONbz

My guess would be out-of-bounds memory access, but I can't find that anywhere... could somebody please help me?

Edit:

Thank you for the replies! It was indeed caused by pow. Didn't expect to it to produce floating point numbers even when fed integers. A lesson learned, I guess. Sometimes I wish for Haskell's ^ (yes, I know it's XOR in c++).

The new submission: http://mirror.codeforces.com/contest/525/submission/11008141

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

»
10 years ago, # |
  Vote: I like it +23 Vote: I do not like it

Yellows use pow, really?

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

I think the problem is on pow(3, n / 2). pow() is a floating point function and it may give different outputs on different platforms or compilers.

So i think using an array to stores the value of 3^x is a better way in this case and hope you can AC it.

»
10 years ago, # |
  Vote: I like it +11 Vote: I do not like it

I guess it is the pow precision thing. See this one