ankushmondal1y2t's blog

By ankushmondal1y2t, history, 2 hours ago, In English

Accepted Submission 272506719 Wrong submission 275696577

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

  • Vote: I like it
  • -4
  • Vote: I do not like it

»
2 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

»
2 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
62 minutes ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

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.