tony4875's blog

By tony4875, history, 14 months ago, In English

Hi codeforces,

Could anyone help me explain why my code got AC in C++20 and C++23 but failed in C++17?

The code is identical for all 3 submissions.
C++17 submission
C++20 submission
C++23 submission

I used C++17 on my local, so I prefer to use C++17 to submit.

Thank you.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
14 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it
r = can.size() - 1;

to

r = static_cast<int>(can.size()) - 1;
  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Thank you

    After changing that, it worked.

    I don't know why it worked, I think can.size() fit with int

    • »
      »
      »
      14 months ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it

      No, can.size() is unsigned, so 0 — 1 = uint32::MAX