結果

問題 No.20 砂漠のオアシス
ユーザー dangodango
提出日時 2023-07-08 18:29:08
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,237 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 85,064 KB
最終ジャッジ日時 2023-09-29 19:48:28
合計ジャッジ時間 4,952 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,264 KB
testcase_01 AC 74 ms
71,348 KB
testcase_02 RE -
testcase_03 WA -
testcase_04 AC 166 ms
79,096 KB
testcase_05 RE -
testcase_06 WA -
testcase_07 AC 266 ms
81,096 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 71 ms
71,372 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 185 ms
79,400 KB
testcase_15 AC 166 ms
78,544 KB
testcase_16 AC 187 ms
78,976 KB
testcase_17 WA -
testcase_18 AC 181 ms
78,744 KB
testcase_19 WA -
testcase_20 AC 132 ms
78,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0