結果
問題 | No.1638 Robot Maze |
ユーザー | nephrologist |
提出日時 | 2021-08-06 21:56:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 146 ms / 2,000 ms |
コード長 | 1,406 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 77,816 KB |
最終ジャッジ日時 | 2024-09-17 01:54:03 |
合計ジャッジ時間 | 5,132 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,224 KB |
testcase_01 | AC | 43 ms
52,736 KB |
testcase_02 | AC | 43 ms
52,352 KB |
testcase_03 | AC | 112 ms
76,800 KB |
testcase_04 | AC | 44 ms
52,480 KB |
testcase_05 | AC | 43 ms
52,736 KB |
testcase_06 | AC | 43 ms
52,992 KB |
testcase_07 | AC | 44 ms
52,480 KB |
testcase_08 | AC | 44 ms
53,248 KB |
testcase_09 | AC | 44 ms
52,864 KB |
testcase_10 | AC | 43 ms
52,480 KB |
testcase_11 | AC | 44 ms
52,992 KB |
testcase_12 | AC | 44 ms
52,480 KB |
testcase_13 | AC | 43 ms
52,608 KB |
testcase_14 | AC | 91 ms
74,624 KB |
testcase_15 | AC | 104 ms
76,928 KB |
testcase_16 | AC | 104 ms
76,928 KB |
testcase_17 | AC | 112 ms
76,588 KB |
testcase_18 | AC | 47 ms
53,504 KB |
testcase_19 | AC | 85 ms
71,296 KB |
testcase_20 | AC | 86 ms
70,656 KB |
testcase_21 | AC | 43 ms
53,376 KB |
testcase_22 | AC | 61 ms
65,536 KB |
testcase_23 | AC | 62 ms
65,408 KB |
testcase_24 | AC | 59 ms
64,512 KB |
testcase_25 | AC | 59 ms
64,384 KB |
testcase_26 | AC | 65 ms
67,456 KB |
testcase_27 | AC | 66 ms
67,456 KB |
testcase_28 | AC | 66 ms
68,736 KB |
testcase_29 | AC | 66 ms
68,992 KB |
testcase_30 | AC | 42 ms
52,352 KB |
testcase_31 | AC | 42 ms
52,352 KB |
testcase_32 | AC | 123 ms
76,880 KB |
testcase_33 | AC | 129 ms
77,616 KB |
testcase_34 | AC | 130 ms
77,132 KB |
testcase_35 | AC | 138 ms
77,816 KB |
testcase_36 | AC | 125 ms
77,076 KB |
testcase_37 | AC | 128 ms
76,912 KB |
testcase_38 | AC | 43 ms
53,504 KB |
testcase_39 | AC | 122 ms
77,212 KB |
testcase_40 | AC | 120 ms
76,800 KB |
testcase_41 | AC | 146 ms
77,528 KB |
testcase_42 | AC | 44 ms
52,992 KB |
testcase_43 | AC | 43 ms
53,120 KB |
testcase_44 | AC | 43 ms
52,864 KB |
testcase_45 | AC | 43 ms
53,376 KB |
testcase_46 | AC | 44 ms
52,864 KB |
testcase_47 | AC | 43 ms
52,992 KB |
testcase_48 | AC | 44 ms
52,864 KB |
testcase_49 | AC | 50 ms
59,392 KB |
testcase_50 | AC | 45 ms
53,120 KB |
testcase_51 | AC | 45 ms
52,864 KB |
ソースコード
import sys from heapq import heappop, heappush input = sys.stdin.readline h, w = map(int, input().split()) def idxtoxy(idx): return idx // w, idx % w def xytoidx(x, y): return x * w + y n = h * w U, D, R, L, K, P = map(int, input().split()) sx, sy, gx, gy = map(int, input().split()) graph = [list(input()) for _ in range(h)] dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] start = xytoidx(sx - 1, sy - 1) goal = xytoidx(gx - 1, gy - 1) cost = [D, R, U, L] def dijkstra(start, graph): infi = 1 << 80 mask = 1 << 18 pq = [] dist = [infi] * n heappush(pq, 0 * mask + start) while pq: temp = heappop(pq) d, v = temp // mask, temp & (mask - 1) if dist[v] <= d: continue if d > K: continue x, y = idxtoxy(v) dist[v] = d if v == goal: return dist[goal] for t in range(4): nx = x + dx[t] ny = y + dy[t] if 0 <= nx < h and 0 <= ny < w: delta = cost[t] if graph[nx][ny] == "#": continue if graph[nx][ny] == "@": delta += P u = xytoidx(nx, ny) nd = d + delta if dist[u] > nd: heappush(pq, nd * mask + u) return dist[goal] print("No" if dijkstra(start, graph) == 1 << 80 else "Yes")