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 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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