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
№ | Пользователь | Рейтинг |
---|---|---|
1 | jiangly | 3977 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3483 |
8 | hos.lyric | 3381 |
9 | gamegame | 3374 |
10 | heuristica | 3358 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 170 |
2 | -is-this-fft- | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
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
Название |
---|
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