_Sherbiny's blog

By _Sherbiny, history, 3 days ago, In English

Hi, I wanted to share something weird that happened to me in the previous round.

After about an hour, I submitted this code for problem D: Submission 306394465

I knew the code had high memory and time complexity, but I was confident it would pass given the constraints. However, I received a Memory Limit Exceeded (MLE) verdict.

After the round, I resubmitted the exact same code using C++ 17, and it passed—with a huge difference in memory usage!

Submission 306462649

I just wanted to share this random incident and ask if anyone knows the reason behind it.

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

»
3 days ago, # |
Rev. 3   Vote: I like it +28 Vote: I do not like it

This happens because of the pointer troubles. In C++23, you receive 8 bytes for a pointer instead of 4 bytes in C++17.

  • »
    »
    3 days ago, # ^ |
      Vote: I like it +75 Vote: I do not like it

    Actually, the size of the pointer has nothing to do with the C++ version.
    In 32 bit processors, pointers are 4 bytes (32 bits).
    In 64 bit processors, pointers are 8 bytes (64 bits).
    The MLE submission used C++23(GCC 14- 64, msys2).
    The Accepted submission used C++17(GCC 7- 32).

    • »
      »
      »
      3 days ago, # ^ |
        Vote: I like it +21 Vote: I do not like it

      Yep, you're right.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

what are people's thoughts on codeforces only allowing c++23?

personally I don't want to think about what's the word size of the computer I'm submitting on, and how that affects the memory usage. Like I'm not interested in how hardware affects time/memory usage.

If codeforces only allowed c++23, it implies problem setter's code should run comfortable on 64-bit machines, implying time/memory limits should be set accordingly

  • »
    »
    46 hours ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    Some code fails to compile on a newer C++ version because a new C++ version introduces identifiers that may conflict with user's code. It's hard to avoid this in Codeforces where using namespace std; is a must. (I'm stuck in C++20 becuase of std::print.)

    My take is that Codeforces should provide options for different C++ versions and bitness (32/64) on the same compiler version. Theoretically it should be not too hard to do it once you have a stable environment for a specific compiler, because you just need to change the command line options (-std=... and -m32/-m64).

    (I think the bigger problem here is that it's apparently very hard for Codeforces to add a new compiler.)

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

    Lots of other platforms, e.g. usaco.org, primarily use C++17. And also, why remove compilers? All that does is make people like us be more restricted. A better idea would be to only support 64 bit systems (whenever possible) for all the C++ versions.

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

I even face troubles with C++20, so I prefer to stick with C++17.