Please read the new rule regarding the restriction on the use of AI tools. ×
Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Zenith_053's blog

By Zenith_053, history, 17 months ago, In English

My code is given WA verdict on G++ 17, and G++ 14, but the same code is accepted on G++ 20 can anyone tell me how this is possible? Question Link My Answer(accepted) My Answer(WA)

  • Vote: I like it
  • +8
  • Vote: I do not like it

| Write comment?
»
17 months ago, # |
Rev. 3   Vote: I like it +14 Vote: I do not like it

It's not about C++14, C++17 vs C++20. It's about 32 bits vs 64 bits.

It seems to me that the failing test case has all bits of the sequence equal to 1. This means that the line printing the answer is this:

if(gate == 0){
    cout << s.size()*s.size() << endl;
}

Notice that the C++14 and C++17 submissions you made were on 32 bits, while the C++20 submission was on 64 bits (compare the language names: GNU C++17 vs GNU C++20 (64); here 32 bits is assumed if 64 bits isn't specified). If the submission is made on 32 bits, vectors and other containers store their sizes as an unsigned 32-bit integer (i.e. the same as an unsigned int). On 64 bits, the size of containers is stored as an unsigned 64-bit integer (i.e. the same as an unsigned long long). Thus, on 32 bits the multiplication will overflow.

There are a few ways to fix this:

  • Cast to long long (recommended)
  • Choose a 64-bit language on submission (there is a 64-bit C++17 option availible if you don't want to use C++20 for some reason)

Here are some submissions for reference: