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??
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 3 | Proof_by_QED | 147 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 142 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| Name |
|---|



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
ya cauze 20 is not complete i think
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!!
Same code TLEs in C++20 (g++11.2) but passes in C++17 (g++9.2) due to slower stdlib/I-O constants