Привет, codeforces, сегодня я апнул 2000, но пост не об этом.
Я заслал решение с трех разных компиляторов и получил три разных вердикта по задаче 1553E - Permutation Shift с последнего раунда
Потом я запустил valgrind (g++ 11.1.0) и обнаружил странные "still reachable" адреса памяти, связанные с ios_base::sync_with_stdio. Потом я обнаружил, что он был в функции solve, которую я вызываю для каждого набора входных данных, а не в main, после чего я перенес его в main и получил OK на всех компиляторах.
valgrind output on sample
==36581==
==36581== HEAP SUMMARY:
==36581== in use at exit: 122,880 bytes in 6 blocks
==36581== total heap usage: 120 allocs, 114 frees, 197,964 bytes allocated
==36581==
==36581== 8,192 bytes in 1 blocks are still reachable in loss record 1 of 6
==36581== at 0x484021F: operator new[](unsigned long) (vg_replace_malloc.c:579)
==36581== by 0x4982194: _M_allocate_internal_buffer (fstream.tcc:56)
==36581== by 0x4982194: std::basic_filebuf<char, std::char_traits<char> >::_M_allocate_internal_buffer() (fstream.tcc:49)
==36581== by 0x497FEBA: __gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, unsigned long) (stdio_filebuf.h:161)
==36581== by 0x492E6A2: std::ios_base::sync_with_stdio(bool) (ios_init.cc:181)
==36581== by 0x109410: solve() (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581== by 0x109AB8: main (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581==
==36581== 8,192 bytes in 1 blocks are still reachable in loss record 2 of 6
==36581== at 0x484021F: operator new[](unsigned long) (vg_replace_malloc.c:579)
==36581== by 0x4982194: _M_allocate_internal_buffer (fstream.tcc:56)
==36581== by 0x4982194: std::basic_filebuf<char, std::char_traits<char> >::_M_allocate_internal_buffer() (fstream.tcc:49)
==36581== by 0x497FEBA: __gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, unsigned long) (stdio_filebuf.h:161)
==36581== by 0x492E6C6: std::ios_base::sync_with_stdio(bool) (ios_init.cc:182)
==36581== by 0x109410: solve() (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581== by 0x109AB8: main (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581==
==36581== 8,192 bytes in 1 blocks are still reachable in loss record 3 of 6
==36581== at 0x484021F: operator new[](unsigned long) (vg_replace_malloc.c:579)
==36581== by 0x4982194: _M_allocate_internal_buffer (fstream.tcc:56)
==36581== by 0x4982194: std::basic_filebuf<char, std::char_traits<char> >::_M_allocate_internal_buffer() (fstream.tcc:49)
==36581== by 0x497FEBA: __gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, unsigned long) (stdio_filebuf.h:161)
==36581== by 0x492E6EA: std::ios_base::sync_with_stdio(bool) (ios_init.cc:183)
==36581== by 0x109410: solve() (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581== by 0x109AB8: main (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581==
==36581== 32,768 bytes in 1 blocks are still reachable in loss record 4 of 6
==36581== at 0x484021F: operator new[](unsigned long) (vg_replace_malloc.c:579)
==36581== by 0x4983F47: _M_allocate_internal_buffer (fstream.tcc:56)
==36581== by 0x4983F47: std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >::_M_allocate_internal_buffer() (fstream.tcc:49)
==36581== by 0x49800BA: __gnu_cxx::stdio_filebuf<wchar_t, std::char_traits<wchar_t> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, unsigned long) (stdio_filebuf.h:161)
==36581== by 0x492E757: std::ios_base::sync_with_stdio(bool) (ios_init.cc:190)
==36581== by 0x109410: solve() (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581== by 0x109AB8: main (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581==
==36581== 32,768 bytes in 1 blocks are still reachable in loss record 5 of 6
==36581== at 0x484021F: operator new[](unsigned long) (vg_replace_malloc.c:579)
==36581== by 0x4983F47: _M_allocate_internal_buffer (fstream.tcc:56)
==36581== by 0x4983F47: std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >::_M_allocate_internal_buffer() (fstream.tcc:49)
==36581== by 0x49800BA: __gnu_cxx::stdio_filebuf<wchar_t, std::char_traits<wchar_t> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, unsigned long) (stdio_filebuf.h:161)
==36581== by 0x492E77B: std::ios_base::sync_with_stdio(bool) (ios_init.cc:191)
==36581== by 0x109410: solve() (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581== by 0x109AB8: main (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581==
==36581== 32,768 bytes in 1 blocks are still reachable in loss record 6 of 6
==36581== at 0x484021F: operator new[](unsigned long) (vg_replace_malloc.c:579)
==36581== by 0x4983F47: _M_allocate_internal_buffer (fstream.tcc:56)
==36581== by 0x4983F47: std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >::_M_allocate_internal_buffer() (fstream.tcc:49)
==36581== by 0x49800BA: __gnu_cxx::stdio_filebuf<wchar_t, std::char_traits<wchar_t> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, unsigned long) (stdio_filebuf.h:161)
==36581== by 0x492E79F: std::ios_base::sync_with_stdio(bool) (ios_init.cc:192)
==36581== by 0x109410: solve() (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581== by 0x109AB8: main (in /home/thematdev/AlgoProgs/tinkoffgeneration2020/tmp/HarbourSpaceScholarship/problemE/a.out)
==36581==
==36581== LEAK SUMMARY:
==36581== definitely lost: 0 bytes in 0 blocks
==36581== indirectly lost: 0 bytes in 0 blocks
==36581== possibly lost: 0 bytes in 0 blocks
==36581== still reachable: 122,880 bytes in 6 blocks
==36581== suppressed: 0 bytes in 0 blocks
==36581==
==36581== For lists of detected and suppressed errors, rerun with: -s
==36581== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Достаточно странная , и самое главное, интересная ситуация, поэтому я прошу знающих людей подсказать в чём была проблема в комментариях.