結果
| 問題 | No.20 砂漠のオアシス |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-01-22 13:28:51 |
| 言語 | PyPy3 (8.0.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 404 ms / 5,000 ms |
| + 3µs | |
| コード長 | 985 bytes |
| 記録 | |
| コンパイル時間 | 104 ms |
| コンパイル使用メモリ | 64,920 KB |
| 実行使用メモリ | 77,992 KB |
| 最終ジャッジ日時 | 2026-10-13 04:39:27 |
| 合計ジャッジ時間 | 4,820 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
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()