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

Автор ankushmondal1y2t, история, 4 часа назад, По-английски

Accepted Submission 272506719 Wrong submission 275696577

both are same code but different verdict why its happening??

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

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

you're using c++14 while they're using c++ 20

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

maybe its because the language? (one is C++ 14 and other is C++ 20)

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

gcc 6-32 uses uint32_t as size_t, but gcc 13-64 uses uint64_t.

The string::npos is defined as size_type npos = -1. Thus in the wrong submission, it is interpreted as $$$2^{32}-1$$$, and then cast into long long so either ia or ib will get $$$2^{32}-1$$$ instead of $$$-1$$$.

In the accepted submission, string::npos is interpreted as $$$2^{64}-1$$$, so ia or ib can get the expected $$$-1$$$.

To avoid this error, you can declare auto ia = s.find(..), and use string::npos instead of -1 explicitly.