結果
問題 | No.34 砂漠の行商人 |
ユーザー | kept1994 |
提出日時 | 2022-05-07 17:43:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,244 ms / 5,000 ms |
コード長 | 1,565 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 87,152 KB |
実行使用メモリ | 413,976 KB |
最終ジャッジ日時 | 2023-09-21 04:28:13 |
合計ジャッジ時間 | 10,460 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 97 ms
71,736 KB |
testcase_01 | AC | 103 ms
76,916 KB |
testcase_02 | AC | 119 ms
77,944 KB |
testcase_03 | AC | 97 ms
71,360 KB |
testcase_04 | AC | 213 ms
115,824 KB |
testcase_05 | AC | 216 ms
127,836 KB |
testcase_06 | AC | 136 ms
99,452 KB |
testcase_07 | AC | 270 ms
153,532 KB |
testcase_08 | AC | 357 ms
181,776 KB |
testcase_09 | AC | 96 ms
71,384 KB |
testcase_10 | AC | 96 ms
71,568 KB |
testcase_11 | AC | 95 ms
71,388 KB |
testcase_12 | AC | 188 ms
116,972 KB |
testcase_13 | AC | 98 ms
71,380 KB |
testcase_14 | AC | 97 ms
71,744 KB |
testcase_15 | AC | 97 ms
71,624 KB |
testcase_16 | AC | 97 ms
71,576 KB |
testcase_17 | AC | 98 ms
71,740 KB |
testcase_18 | AC | 101 ms
71,524 KB |
testcase_19 | AC | 1,885 ms
357,940 KB |
testcase_20 | AC | 3,244 ms
413,976 KB |
testcase_21 | AC | 244 ms
212,896 KB |
testcase_22 | AC | 97 ms
71,536 KB |
testcase_23 | AC | 96 ms
71,628 KB |
testcase_24 | AC | 95 ms
71,364 KB |
testcase_25 | AC | 326 ms
165,536 KB |
ソースコード
#!/usr/bin/env python3 import sys from collections import deque MOD = 998244353 input = sys.stdin.readline powerMax = 99 * 2 * 9 INF = 10 ** 16 def main(): N, V, Sx, Sy, Gx, Gy = map(int, input().split()) if V > (abs(Sx-Gx) + abs(Sy-Gy)) * 9: print(abs(Sx-Gx) + abs(Sy-Gy)) return V = min(V, powerMax) Grid = [list(map(int, input().split())) for _ in range(N)] def bfs(G, H, W, startY, startX, goalY, goalX, power_init) -> list: q = deque() dist = [[[INF] * (powerMax + 1) for _ in range(W)] for _ in range(H)] q.append((startY, startX, power_init)) dist[startY][startX][power_init] = 0 while q: nowY, nowX, now_power = q.popleft() if nowY == goalY and nowX == goalX: return dist[nowY][nowX][now_power] for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]: nexty = nowY + dy nextx = nowX + dx if nexty < 0 or nextx < 0 or nexty >= H or nextx >= W: continue next_power = now_power - G[nexty][nextx] if next_power <= 0 or dist[nexty][nextx][next_power] != INF: continue q.append((nexty, nextx, next_power)) dist[nexty][nextx][next_power] = dist[nowY][nowX][now_power] + 1 return -1 print(bfs(Grid, N, N, Sy - 1, Sx - 1, Gy - 1, Gx - 1, V)) # ans = min(dist[Gy - 1][Gx - 1][1:]) # print(ans if ans != INF else -1) return if __name__ == '__main__': main()