Today I was solving this problem 632C - The Smallest String Concatenation.
The judge's response for this code 18114819 was Runtime error on test 8.
Then I changed only the last line in the sort comparison function (comp function) from (return true) to (return false) (code: 18114847), and the judge's response was Accepted.
Does anyone have an explanation for that?
Thank you.
Your comparator returns 1 for comp(a, a) which is incorrect.
Thank you for the explanation.
1800+ guy asking this... Well, I have an explanation in just four letters!
RTFM
Thank you for your high morals.
LOL!! You're participating for more than 5 years and still violet!!
Why so harsh? It's one of trickier technical details.
I'm violet because I'm not able to solve hard problems. Everyone has their limits in different areas and it can't be fixed. From the other side, everyone is able to read a language manual. When I use a function, I read its docs. And you? The topicstarter doesn't. He didn't even try to find it in Google or Stackoverflow.
I will surprise you but ability of understanding manuals and efficient googling is also a skill one can be good or bad at it. For example, I am at most cyan at both :). Even if it is possible that I will be able to find an answer in Google I often choose to ask somebody, because a friend will probably understand me better than Google.
Well. I have an explanation in just three letters!
PMS
Becuase
std::sort
is usingoperator <
as a parameter, it is incorrect to use function which returns true in case of equality. This might sometimes end up in an RE. Not sure when exactly, but in most cases it will.Thank you for the explanation.
The comparator function must meet the requirements of Compare concept i.e if comp(a,b) = true then comp(b,a) must return false and vice versa . Runtime error can occur in case where you have used <= or >= in your custom comparator function . hope you got it
After 4 years I would hope he got it too...