zhugezy's blog

By zhugezy, history, 3 years ago, In English

I met with some weird problems when solving https://mirror.codeforces.com/contest/1599/problem/C The question is simple, but plz take a look at these 4 submissions below:

Case 1:

https://mirror.codeforces.com/contest/1599/submission/133010155

https://mirror.codeforces.com/contest/1599/submission/133010068

The only difference is the "inline" of the function double mypr.

Take a look at the test cases for more information.

Case 2:

https://mirror.codeforces.com/contest/1599/submission/133012557

https://mirror.codeforces.com/contest/1599/submission/133012618

The only difference is the "cout" line in function int solve.

Also take a look at the test cases for more information.

Compiler: GNU G++14 6.4.0

Everything works fine on my local environment, G++11/14 or else.

So is there any problem with codeforces, or is it my fault?

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

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

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

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

Worse still, I got AC when I copied your WA code in Case 1 and ran it on C++20, but it would be wrong in C++17... https://mirror.codeforces.com/contest/1599/submission/133026237

Could it be the implementation?

»
3 years ago, # |
  Vote: I like it +19 Vote: I do not like it

Observing The Universe Really Does Change The Outcome, And This Experiment Shows How

When you use cout, you "observe" it, I think it has something to do with Quantum Entanglement.

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

I think the WA is caused by this line if (temp >= p) return m;. When temp is equal to p, the judgment may still be false due to the precision of floating point numbers,

You show that gcc is not stable when compiling different codes, although their logic is exactly the same. So I guess it will pass by changing the code like this if (temp >= p - 1e-6) return m;. 133048370

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +10 Vote: I do not like it

    So looks like it's some kind of compiler issues leading to different compiling behaviours. May try going deep into it.

    Very useful, thx!