My Python code got a TLE (335955836) in 2135A - Against the Difference. However, when I switched from PyPy3-64 to Python 3, the code passed the tests (336071570), far within the time limit.
Are there any known caveats of using PyPy3 on codeforces?
My Python code got a TLE (335955836) in 2135A - Against the Difference. However, when I switched from PyPy3-64 to Python 3, the code passed the tests (336071570), far within the time limit.
Are there any known caveats of using PyPy3 on codeforces?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | jiangly | 3631 |
| 4 | Kevin114514 | 3574 |
| 5 | maroonrk | 3521 |
| 6 | strapple | 3515 |
| 7 | Radewoosh | 3461 |
| 8 | tourist | 3428 |
| 9 | turmax | 3378 |
| 10 | Um_nik | 3376 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 161 |
| 2 | adamant | 147 |
| 3 | Um_nik | 145 |
| 4 | Dominater069 | 142 |
| 5 | errorgorn | 140 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
| Name |
|---|



That's because you used
dict. Inserting an element to asetor adictis worst-case $$$O(n)$$$, and it's possible to construct a test case that causes this (read more about anti-hash-table tests).Implementation of
setanddictis different in Python and PyPy, and it's possible that an anti-hash test case only works in PyPy (or vice versa).FYI, here's the hack test case used here.
For more information:
Python and PyPy were supposed to have the same implementation for hashtables but a wise person once told me that there was a translation bug which is why hacks for PyPy don't do anything to Python submissions and conversely: https://github.com/pypy/pypy/issues/3724#issuecomment-1872105847
95% of my submissions are in PyPy not Python normally coz it is nearly always faster and I got this problem ACC yesterday with your same idea nearly, the thing I am doing in these problems that hates Python are always look at a[i] if it is a[i] <= n or so, don't use dictionary just use array, when it is not maybe its a different solution or if I really wanna do hashing I will do d[str(a[i])] = "bla bla", coz I made a similar blog before and someone told me that and it worked, so use it always but be careful about this and switch to cpp when it comes to recursion and graph things or too tight problems and big arrays.
Just to say I try to do iterative when recursion is needed (e.g. dfs)
In this particular exercise you don't need to use dict. You can keep track of indexes with arrays 335981674
Sir, I have always been told that PyPy is faster than Python 3. Your case is truly a mystery.
same
I love you pypy.