結果
| 問題 | No.20 砂漠のオアシス |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-08 18:29:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,237 bytes |
| 記録 | |
| コンパイル時間 | 156 ms |
| コンパイル使用メモリ | 82,588 KB |
| 実行使用メモリ | 79,116 KB |
| 最終ジャッジ日時 | 2024-07-22 13:53:40 |
| 合計ジャッジ時間 | 3,821 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 9 RE * 2 |
ソースコード
from heapq import heappush, heappop
n, v, ox, oy = map(int, input().split())
field = [list(map(int, input().split())) for _ in range(n)]
INF = 40000
q = []
first = [[-INF] * n for _ in range(n)]
second = [[-INF] * n for _ in range(n)]
heappush(q, (-v, 0))
first[0][0] = v
while q:
life, pos = heappop(q)
life = -life
y = pos // 1000
x = pos % 1000
for dy, dx in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
ny = y + dy
nx = x + dx
if ny < n and nx < n and first[ny][nx] == -INF:
first[ny][nx] = life - field[ny][nx]
heappush(q, (-first[ny][nx], ny * 1000 + nx))
if ox != 0 or oy != 0:
oy -= 1
ox -= 1
second[oy][ox] = first[oy][ox] * 2
heappush(q, (-second[oy][ox], oy * 1000 + ox))
while q:
life, pos = heappop(q)
life = -life
y = pos // 1000
x = pos % 1000
for dy, dx in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
ny = y + dy
nx = x + dx
if ny < n and nx < n and second[ny][nx] == -INF:
second[ny][nx] = life - field[ny][nx]
heappush(q, (-second[ny][nx], ny * 1000 + nx))
print("YES" if first[n - 1][n - 1] > 0 or second[n - 1][n - 1] > 0 else "NO")