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

Автор rohit_1402, 6 лет назад, По-английски

In educational round 88 Problem C I have submitted my solution in GNU C++17 (64) it gives WA on test 4 at the time of contest. But today I have submitted my same code in GNU C++ 17 and it is accepted.

Code submitted in GNU C++ 17 (64)

Code submitted in GNU C++ 17

Both are the same code

Can anyone tell me why it is so??

UPD: Now I have use long double instead of double and submitted the same code using GNU C++17 (64) compiler and it is AC. But by just using double why it was giving WA using GNU C++17 (64) and AC using GNU C++17 ?

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

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

same happened with me.

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

Try to use abs(a - b) < EPS instead of a == b.

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

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

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

Try running this code using g++ 17 and g++ 17 (64)

Sample_code

You can read the 4th point here to understand the details of what is happening here.

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

It is not compiler's bug. Read http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html to understand that floating-point arithmetic has rules on its own.

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

Raid works wonders against bugs.

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

this causes me to -75 in the last contest.....

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

I just posted a blog on the subject https://codeforces.me/blog/entry/78161 . In 32 bit g++ all floating point arithmetic is done using (80 bit) long double, which creates a kind of excess precision. However in 64 bit g++ it does the floating point arithmetic using each corresponding type. This results in less precision but also more "deterministic" behavior.

It possible to turn on excess precision even on 64 bit g++, this is done with the flag -mfpmath=387. With it your code gets AC in 64 bit g++ 81987643. It is also possible to make you get WA in 32 bit g++ by turning off excess precision using -mfpmath=sse -msse2 81995764.