Блог пользователя alumkal

Автор alumkal, история, 15 месяцев назад, По-английски

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?

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +27 Проголосовать: не нравится

That's because you used dict. Inserting an element to a set or a dict is 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 set and dict is 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.

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In this particular exercise you don't need to use dict. You can keep track of indexes with arrays 335981674

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

I love you pypy.