This problem 2061D - Kevin and Numbers, i just solved today.
initially i was getting a TLE 335481507 in C++20,
but when i switched to C++17 ans pasted the exact same code 335481556 ,it got Accepted !!
Can anyone tell why is this happening??
This problem 2061D - Kevin and Numbers, i just solved today.
initially i was getting a TLE 335481507 in C++20,
but when i switched to C++17 ans pasted the exact same code 335481556 ,it got Accepted !!
Can anyone tell why is this happening??
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Kevin114514 | 3722 |
| 2 | Benq | 3676 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3196 |
| 10 | idontwannadothis…e | 3191 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | maroonrk | 153 |
| 2 | Qingyu | 152 |
| 3 | nik_exists | 151 |
| 4 | AmShZ | 147 |
| 4 | maspy | 147 |
| 6 | Um_nik | 143 |
| 7 | Errichto | 139 |
| 8 | adamant | 136 |
| 9 | BledDest | 134 |
| 10 | AksLolCoding | 132 |
| Название |
|---|



I think this has to do with the fact CodeForces C++20 is 64-bit and uses 64-bit memory addresses and C++17 32-bit. There are other blogs about this
The reason for the TLE is that the time complexity of
con.count(x)is $$$O(\log(con.size()) + con.count(x))$$$ (see std::multiset::count).So, your code is $$$O(n \times m)$$$.
It did not TLE in [GCC 7.3.0 32-bit C++17] because that version of GCC recognizes expressions of the form
con.count(x) > 0and optimizes them tocon.find(x) != con.end()which are only $$$O(\log(con.size()))$$$. Of course, such optimizations are inconsistent and one should always do the conversion manually.Regarding some other comments: This has nothing to do with the bitness of the architecture. The memory usage displayed for the C++20 submission is actually less then the C++17 submission (since it TLE'd before allocating more memory). Also, the incomplete support for C++20 will not make a difference in CP since the only incomplete C++20 feature in gcc is modules.
Sometimes the C++17 compiler makes this optimization, sometimes it doesn't: this solution TLEs while this solution doing the conversion manually passes. I think that the C++23 compiler always makes this optimization (the same solution that TLEd with C++17 ACs with C++23) but I'm not entirely sure.
Regardless, with C++20 or higher you can use
multiset::contains.got it,thanks a lot buddy!!