Strange situation(three different results with different compilers)

Правка en4, от thematdev, 2021-07-22 23:42:15

Hello, Codeforces.

I've sent three submissions with different compilers on problem 1553E - Permutation Shift from last round and got different results(OK, ML 1, WA 1)

123344376

123363613

123363479

Then i've ran valgrind (g++ 11.1.0) and discovered strange "still reachable" memory addresses, somehow connected with ios_base::sync_with_stdio. Then I realised, that fast IO was in solve function, which is called in main $$$T$$$ times for each test case. Then I moved it to main and got OK in all compilers.

valgrind output on sample

Pretty strange and interesting situation, so I am asking those, who know what's the problem to write about it in comments. Also I am glad to see critics of my code, especially if it will help to avoid situations like this.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский thematdev 2021-07-22 23:42:15 0 (published)
ru4 Русский thematdev 2021-07-22 23:41:54 0 (опубликовано)
ru3 Русский thematdev 2021-07-22 23:41:32 129
en3 Английский thematdev 2021-07-22 23:40:01 86 Tiny change: 'he problem, write abo' -> 'he problem to write abo'
en2 Английский thematdev 2021-07-22 23:30:10 55
en1 Английский thematdev 2021-07-22 23:28:27 6876 Initial revision for English translation (saved to drafts)
ru2 Русский thematdev 2021-07-22 23:21:36 127
ru1 Русский thematdev 2021-07-22 23:19:58 6769 Первая редакция (сохранено в черновиках)