atcoder F - Pond Skater ABC170
According to the explanation, it is the Dijkstra method.
Once the WA returns the number of edges that make up the path instead of the sum of the costs, the WA
python
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', '(b1[:],i8,i8,i8,i8,i8)')(main)
cc.compile()
exit()
from my_module import main
https://atcoder.jp/contests/abc170/submissions/14405996 Oh my god. It's pre-compiled by numba.
Right now, we're as far as we can go in a straight line.
49 20156497 22145363.0 1.1 11.3 nx += dxHard to believe it's only about 10% slower in a situation like this, huh?
3314 ms in PyPy3, exceeding the time limit by 10%. (Misunderstanding A)
Fixed a bug where the distance update on orientation change was wrong, submit, WA.
The reason for the WA was that the distance was now a tuple of two numbers, but the determination of unreachability was still based on a comparison to one number.
7.3 (d, frac), (frm, direction) = heappop(queue)
8.5 for dir in range(4):
6.0 if dir == direction:
5.3 if nx < 1 or H < nx or ny < 1 or W < ny:
7.7 dp(nx, ny, mapdata[nx - 1][ny - 1])
5.4 if mapdata[nx - 1][ny - 1] == leaf:
5.7 if distances[to] > newdist:
Comment out debug printouts that you forgot to erase.
I'm running a 4-way direction minus the one I'm facing now, but I might as well shatter this loop.
Total execution time went from 80 seconds to 27 seconds. Let's submit.
11.1 (d, frac), (frm, direction) = heappop(queue)
- Hmmm, well, yes...
- I'm not really motivated to fix this area.
Try NUMBA.
input is said to be of unknown type, so read it outside main and then pass it on.
Untyped global name 'input': cannot determine Numba type of <class 'builtin_function_or_method'>How do you give them the map? Ah, I see, you make it a one-dimensional array with a guard. - One-dimensional array with guard
b1[:]Untyped global name 'defaultdict': cannot determine Numba type of <class 'numba.core.ir.UndefinedType'>
Use of unsupported opcode (IMPORT_NAME) found
After all, you can't key a tuple. -like
No implementation of function Function(<built-in function setitem>) found for signature:>>> setitem(DictType[Tuple(UniTuple(int64 x 2), int64),UniTuple(int64 x 2)], Tuple(UniTuple(int64 x 2), Literal[int](0)), none)Key error due to quit defaultdict is not where it happened in the compiled situation, so run in Python mode
Mysterious error 'NoneType' object has no attribute 'args'.
It seems that get from dictionary makes the type wrong, so I reimplemented it with a list so that it does not get from a dictionary.
In the process of speeding up, only a 90-degree turn was made, which meant that the first move was one more answer on the board directly behind.
I only made the fifth orientation the first time, but maybe I should have just made two 90-degree rotations of the starting state.
This page is auto-translated from /nishio/ABC170_F using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.