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?

Full text and comments »

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