My code is given WA verdict on G++ 17, and G++ 14, but the same code is accepted on G++ 20 can anyone tell me how this is possible? Question Link My Answer(accepted) My Answer(WA)
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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 |
My code is given WA verdict on G++ 17, and G++ 14, but the same code is accepted on G++ 20 can anyone tell me how this is possible? Question Link My Answer(accepted) My Answer(WA)
Название |
---|
It's not about C++14, C++17 vs C++20. It's about 32 bits vs 64 bits.
It seems to me that the failing test case has all bits of the sequence equal to 1. This means that the line printing the answer is this:
Notice that the C++14 and C++17 submissions you made were on 32 bits, while the C++20 submission was on 64 bits (compare the language names: GNU C++17 vs GNU C++20 (64); here 32 bits is assumed if 64 bits isn't specified). If the submission is made on 32 bits, vectors and other containers store their sizes as an unsigned 32-bit integer (i.e. the same as an unsigned int). On 64 bits, the size of containers is stored as an unsigned 64-bit integer (i.e. the same as an unsigned long long). Thus, on 32 bits the multiplication will overflow.
There are a few ways to fix this:
Here are some submissions for reference: