結果
問題 | No.20 砂漠のオアシス |
ユーザー |
|
提出日時 | 2020-05-01 00:31:09 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,397 bytes |
コンパイル時間 | 506 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-12-18 00:40:04 |
合計ジャッジ時間 | 2,892 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 WA * 2 |
ソースコード
import heapq N, V, Ox, Oy = map(int, input().split()) Ox -= 1 Oy -= 1 L = [[int(j) for j in input().split()] for i in range(N)] already = [[False for i in range(N)] for j in range(N)] already[0][0] = True queue = [] heapq.heappush(queue, (L[0][0], 0, 0)) course = [(0, 1), (1, 0), (-1, 0), (0, -1)] s = 0 while queue: tmp = heapq.heappop(queue) for i in course: y, x = tmp[1] + i[0], tmp[2] + i[1] if x < 0 or y < 0 or x >= N or y >= N: continue if already[y][x]: continue if (v := tmp[0] + L[y][x]) >= V: continue already[y][x] = True heapq.heappush(queue, (v, y, x)) if y == Oy and x == Ox: s = v if already[N - 1][N - 1]: print('YES') exit() if (Ox == -1 and Oy == -1) or not already[Oy][Ox]: print('NO') exit() already = [[False for i in range(N)] for j in range(N)] s -= V - s heapq.heappush(queue, (s, Oy, Ox)) while queue: tmp = heapq.heappop(queue) for i in course: y, x = tmp[1] + i[0], tmp[2] + i[1] if x < 0 or y < 0 or x >= N or y >= N: continue if already[y][x]: continue if (v := tmp[0] + L[y][x]) >= V: continue already[y][x] = True heapq.heappush(queue, (v, y, x)) if already[N - 1][N - 1]: print('YES') else: print('NO')