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

Автор zhugezy, история, 3 года назад, По-английски

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?

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

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится +19 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

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 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

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

    Very useful, thx!