結果
問題 | No.20 砂漠のオアシス |
ユーザー |
|
提出日時 | 2023-07-09 15:22:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 266 ms / 5,000 ms |
コード長 | 741 bytes |
コンパイル時間 | 436 ms |
コンパイル使用メモリ | 82,424 KB |
実行使用メモリ | 78,816 KB |
最終ジャッジ日時 | 2024-07-23 12:20:27 |
合計ジャッジ時間 | 3,675 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
import heapqN, V, x, y = map(int, input().split())O = (x - 1, y - 1)G = (N - 1, N - 1)L = [list(map(int, input().split())) for i in range(N)]dxy = ((1, 0), (0, 1), (-1, 0), (0, -1))D = [[0] * N for i in range(N)]D[0][0] = -VQ = []heapq.heappush(Q, (-V, (0, 0), True))while Q:v, h, f = heapq.heappop(Q)if h == G:print("YES")breakfor dx, dy in dxy:nx = h[0] + dxny = h[1] + dyif 0 <= nx < N and 0 <= ny < N:n = (nx, ny)nv = v + L[ny][nx]if f and n == O:nv *= 2f = Falseif nv < D[ny][nx]:D[ny][nx] = nvheapq.heappush(Q, (nv, n, f))else:print("NO")