In last night AtCoder Beginner Contest, my submission for problem D received a Compile Error verdict using GCC (link). That very same code (besides including some library manually because Clang doesn't have bits/stdc++.h
) got accepted when I used Clang (link).
More on the error, I tried to read the error message and it seemed to be an error about std::set
. However the message was too long for me to either understand it or google it (man I hate C++ error messages).
Error message is included in the submission link but if anyone's interested here it is
Can anyone give me some insights on this problem?
Use this comparator:
The submission got AC, can you please tell why adding const made it AC?
These are const member functions, which are not allowed to:
You can find more explanations here.
Comparator used in STL algorithms/containers is expected to be const member functions because it does not make sense to modify values inside a comparator.
Then how could my code compile and run in Clang?
I don't know why your code compiles on clang. If you look at your submission, your code generates warning about non-const comparator:
Just write
if((int)pile[a.id].size() == k)
instead ofif(pile[a.id].size() == k)
in both lines 56 and 74. This sort of issue occurs in many compilers.meanwhile c++20 has
ssize()