dotsdog's blog

By dotsdog, history, 2 months ago, In English

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?

  • Vote: I like it
  • +18
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it +18 Vote: I do not like it

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)