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

Автор laughing_philosopher, история, 13 месяцев назад, По-английски

I was solving the problem — https://codeforces.me/contest/976/problem/C

I got runtime Error for this submission — https://codeforces.me/contest/976/submission/332127114

But an AC for — https://codeforces.me/contest/976/submission/332127380

and the only difference between these two codes is use of stable_sort() (in AC sub) and sort() (in WA sub). When I searched on the internet I found out that the key difference between sort() and stable_sort() lies in their guarantee regarding the relative order of equivalent elements. But why would this lead to STATUS_ACCESS_VIOLATION?

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

»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +19 Проголосовать: не нравится
else {
   if (a.first.second >= b.first.second)
      return true;
   else
      return false;
}

This part contains error. Change it to if (a.first.second > b.first.second). Reason: It is because the compare function must return false for equal elements. You can go to this link (http://www.cplusplus.com/reference/algorithm/sort/).

Also, https://codeforces.me/blog/entry/52037