i was coding solution for the problem C. The Smallest String Concatenation . the solution depends mainly on overriding the cmp() function. first version caused RTE
bool cmp(const string &a, const string &b){ return a+b <= b+a; }
second version Accepted without = sign.
bool cmp(const string &a, const string &b){ return a+b < b+a; }
why the = sign caused RTE ?
UPD : RTE submission http://codeforces.net/contest/632/submission/20033016
Can you provide a link to your submissions please.
Cycle.
Cycle : could you explain more clearly ?
I just think that in this case sort function can't determine the exact order of equal strings, since there are cyclic relations.
Let's consider comparing string a with string b and their concatenation is equal it must return true that a can become before b .. is there any scenario that sort function will ask about comparison between b and a again !! ?
http://stackoverflow.com/questions/32263560/errorinvalid-comparator-when-sorting-using-custom-comparison-function
Here the guy says that sort requires "strict weak ordering".
http://stackoverflow.com/questions/979759/operator-and-strict-weak-ordering
And here the second comment says that "object must be equivalent to itself, i.e both f (x, y) and f (y, x) must be false, where x == y" but your comparator don't satisfy this condition. For example, you have string a = "xx" and string b = "xx" and a <= b && b <= a so, a is not equivalent to b. :D
Comparators in C++ are different than Java. In C++ you should always return strictly bigger or smaller. Unlike Java where equality is okay.
I'm not sure about details, but for comparing stuff, always use < or > in C++. ( At least in terms of what is commonly used for CP).
RTE happens because it can't decide which should come first, kind of a cyclic bigger than or equal like a guy pointed above.