Блог пользователя my_tempo

Автор my_tempo, история, 3 года назад, По-английски

Link It's a simple problem with a simple solution, But still I'm not able to figure out why is there runtime error on a couple of test cases.

Program
  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

You should change the line if (s1.size() == s2.size()) return true; to if (s1.size() == s2.size()) return false;

Check out https://codeforces.com/blog/entry/57036?#comment-406911 for the reason.

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится

Here and on a more practical note here. The second one is more useful, and it describes all of the conditions you need for a valid sorting order in C++. Comparators use a strict-weak ordering, which means that they should satisfy irreflexivity, transitivity, and transitivity of equivalence. Your comparator doesn't satisfy irreflexivity, so it sometimes throws a runtime error.