Strange situation(three different results with different compilers)

Revision en3, by thematdev, 2021-07-22 23:40:01

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.

History

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