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

Автор dotsdog, история, 6 часов назад, По-английски

I thought to play with Python (which I use for work) and solve the last contest.

For problem C I wrote a very simple code:

import numpy as np
for _ in range(int(input())):
    x, y, k = map(int, input().split())
    tx = int(np.ceil(x/k))
    ty = int(np.ceil(y/k))
    ans = 2*tx - 1 if tx > ty else 2*ty
    print(ans)

Which PyPy 3.10 refused to compile (ModuleNotFoundError: No module named 'numpy'). A bit strange, but ok.

Surely Python 3.8 should have numpy (how can one live without?!), and indeed, that got compiled and gave correct answers. But it was a bit slow (155 ms for 3 test cases), so I wanted to see if just importing the module costs so much time. So I tried to compile the following code:

import numpy as np
for _ in range(int(input())):
    x, y, k = map(int, input().split())
    tx = 0#int(np.ceil(x/k))
    ty = 0#int(np.ceil(y/k))
    ans = 2*tx - 1 if tx > ty else 2*ty
    print(ans)

... which refused to compile (in the same Python 3.8!) claiming that... "ModuleNotFoundError: No module named 'numpy'"!

How could that be possible?

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

»
6 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

it must be judge dependent, since codeforces is running on multiple judges, some may have np, while others don't

»
2 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

i dont know why numpy worked, since i'm pretty sure numpy isnt supposed to be able to be used in python on codeforces (makes python faster)