結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-22 13:28:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 557 ms / 5,000 ms |
| コード長 | 985 bytes |
| コンパイル時間 | 715 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 82,560 KB |
| 最終ジャッジ日時 | 2024-11-27 09:54:50 |
| 合計ジャッジ時間 | 5,391 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
import sys
import heapq
input = sys.stdin.readline
def main():
N, V, Ox, Oy = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
vis = [[[False]*N for i in range(N)] for i in range(2)]
Q = [(-V, 0, 0, False)]
while len(Q) > 0:
hp, r, c, oa = heapq.heappop(Q)
hp = -hp
if vis[1 if oa else 0][r][c]:
continue
if r == c == N-1:
print('YES')
return
vis[1 if oa else 0][r][c] = True
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nr, nc = r + dx, c + dy
if 0 <= nr < N and 0 <= nc < N:
nhp = hp - L[nr][nc]
if nhp > 0:
noa = oa
if not oa and (nr, nc) == (Oy-1, Ox-1):
noa = True
nhp *= 2
heapq.heappush(Q, (-nhp, nr, nc, noa))
print('NO')
if __name__ == '__main__':
main()