hello everyone
i'm trying to sort a vector using an explicit compare function
why does this simple code gives me Runtime Error sometimes and sometime Time Limit Exceeded
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3885 |
3 | jqdai0815 | 3682 |
4 | Benq | 3580 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3506 |
7 | ecnerwala | 3505 |
8 | Radewoosh | 3457 |
9 | Kevin114514 | 3377 |
10 | gamegame | 3374 |
# | User | Contrib. |
---|---|---|
1 | cry | 170 |
2 | -is-this-fft- | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 157 |
5 | Dominater069 | 157 |
7 | adamant | 154 |
8 | luogu_official | 152 |
8 | awoo | 152 |
10 | TheScrasse | 147 |
hello everyone
i'm trying to sort a vector using an explicit compare function
why does this simple code gives me Runtime Error sometimes and sometime Time Limit Exceeded
Name |
---|
Short answer: You should change:
to
can you give me the long answer please ?
Here are the requirements for a Compare function: cppreference Basically the compare function needs to define a strict weak ordering. If your compare function returns true, you're telling the sort function that the first value has to appear before the second element. So if
cost(f) == cost(s)
, then the program thinks that the valuef
has to appear befores
, and alsos
has to appear beforef
(becausecost(s) == cost(f)
). So it doesn't know what to do and gives a runtime error.Maybe this is helpful?
EDIT: Sniped
Jakube
dpaleka
thank you very much
I have just tried to compile and run your code using GNU C++17 Custom Invocation in CF
The following is the program output:
Done
=====
Used: 2839 ms, 3660 KB
The following is the program output after replacing the
<=
operator with<
operator in thecomp
function.Done
=====
Used: 15 ms, 3680 KB
i really don't know why this worked ,, sorry