Why does this code is RTE ?!
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
Name |
---|
Your comparison function is incorrect. For example it returns
true
for 0 and 0 which should never happen for correctless than
comparison.That's true but what's the problem ? If two equal values are swapped in the array it will cauz no effect.
Well first of all, even this is already enough according to C++ standard to lead to undefined behaviour so you can't expect anything after doing sort like that. But in reality I think your comparison function acts very weird in other cases too, like:
I don't think it can be well defined what sort should do in this case.
C++ assumes that your comparator is strict "less than" operator, not the "less than or equal to". So the followings must be satisfied, otherwise you'll get weird result.
1) if func(a, b) is true, then func(b, a) must be false 2) if func(a, b) and func(b, c) is true, then func(a, c) must be true 3) func(a, a) must be false