結果
問題 |
No.20 砂漠のオアシス
|
ユーザー |
|
提出日時 | 2019-10-25 15:07:29 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 772 ms / 5,000 ms |
コード長 | 903 bytes |
コンパイル時間 | 181 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 19,644 KB |
最終ジャッジ日時 | 2024-07-19 19:06:24 |
合計ジャッジ時間 | 4,583 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
from heapq import heappush, heappop from collections import defaultdict N, V, X, Y = map(int, input().split()) X -= 1 Y -= 1 L = [list(map(int, input().split())) for _ in range(N)] que = [(-V, 0, 0, False)] # life, x, y, usedO maxLife = defaultdict(lambda : -float('inf')) while que: life, x, y, usedO = heappop(que) life *= -1 if x == X and y == Y and not usedO: life *= 2 usedO = True if life <= 0: continue if x == y == N - 1: print('YES') exit() if maxLife[(x, y, usedO)] >= life: continue maxLife[(x, y, usedO)] = life for nx in [x - 1, x + 1]: if 0 <= nx < N and life - L[y][nx] > 0: heappush(que, (-(life - L[y][nx]), nx, y, usedO)) for ny in [y - 1, y + 1]: if 0 <= ny < N and life - L[ny][x] > 0: heappush(que, (-(life - L[ny][x]), x, ny, usedO)) print('NO')