結果
問題 | No.34 砂漠の行商人 |
ユーザー | tnodino |
提出日時 | 2022-02-16 05:18:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 144 ms / 5,000 ms |
コード長 | 948 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 87,124 KB |
実行使用メモリ | 78,604 KB |
最終ジャッジ日時 | 2023-09-11 17:06:47 |
合計ジャッジ時間 | 4,870 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
71,772 KB |
testcase_01 | AC | 92 ms
71,784 KB |
testcase_02 | AC | 110 ms
76,852 KB |
testcase_03 | AC | 104 ms
77,384 KB |
testcase_04 | AC | 114 ms
77,536 KB |
testcase_05 | AC | 118 ms
77,572 KB |
testcase_06 | AC | 112 ms
77,488 KB |
testcase_07 | AC | 123 ms
77,680 KB |
testcase_08 | AC | 125 ms
77,188 KB |
testcase_09 | AC | 124 ms
77,784 KB |
testcase_10 | AC | 144 ms
78,604 KB |
testcase_11 | AC | 117 ms
77,476 KB |
testcase_12 | AC | 112 ms
77,668 KB |
testcase_13 | AC | 128 ms
78,000 KB |
testcase_14 | AC | 127 ms
77,960 KB |
testcase_15 | AC | 116 ms
77,532 KB |
testcase_16 | AC | 115 ms
77,704 KB |
testcase_17 | AC | 118 ms
77,560 KB |
testcase_18 | AC | 103 ms
77,412 KB |
testcase_19 | AC | 125 ms
77,536 KB |
testcase_20 | AC | 132 ms
78,028 KB |
testcase_21 | AC | 107 ms
77,688 KB |
testcase_22 | AC | 122 ms
77,200 KB |
testcase_23 | AC | 114 ms
77,432 KB |
testcase_24 | AC | 124 ms
78,228 KB |
testcase_25 | AC | 119 ms
77,656 KB |
ソースコード
from collections import deque def bfs(H, W, L, V, sx, sy, gx, gy): INF = 1<<32 dx = [0, 0, -1, 1] dy = [-1, 1, 0, 0] Cost = [[INF] * W for _ in range(H)] Cost[sx][sy] = 0 Queue = deque() Queue.append((sx, sy, 0)) ret = INF while Queue: x,y,cnt = Queue.popleft() for i in range(len(dx)): nx,my = x + dx[i], y + dy[i] if nx < 0 or H <= nx or my < 0 or W <= my: continue if Cost[x][y] + L[nx][my] < Cost[nx][my] and Cost[x][y] + L[nx][my] < V: Cost[nx][my] = Cost[x][y] + L[nx][my] Queue.append((nx, my, cnt+1)) if nx == gx and my == gy: ret = min(ret, cnt+1) if ret == INF: ret = -1 return ret N,V,Sy,Sx,Gy,Gx = map(int,input().split()) Sx -= 1 Sy -= 1 Gx -= 1 Gy -= 1 L = [list(map(int,input().split())) for _ in range(N)] print(bfs(N, N, L, V, Sx, Sy, Gx, Gy))