結果

問題 No.20 砂漠のオアシス
ユーザー dangodango
提出日時 2023-07-09 15:22:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 306 ms / 5,000 ms
コード長 741 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 86,288 KB
実行使用メモリ 80,608 KB
最終ジャッジ日時 2023-09-30 18:41:55
合計ジャッジ時間 4,787 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,244 KB
testcase_01 AC 78 ms
71,248 KB
testcase_02 AC 77 ms
71,328 KB
testcase_03 AC 131 ms
78,244 KB
testcase_04 AC 148 ms
77,816 KB
testcase_05 AC 306 ms
80,608 KB
testcase_06 AC 165 ms
78,856 KB
testcase_07 AC 234 ms
79,264 KB
testcase_08 AC 152 ms
78,220 KB
testcase_09 AC 226 ms
78,800 KB
testcase_10 AC 76 ms
71,172 KB
testcase_11 AC 77 ms
71,392 KB
testcase_12 AC 127 ms
78,132 KB
testcase_13 AC 123 ms
78,036 KB
testcase_14 AC 153 ms
78,460 KB
testcase_15 AC 145 ms
78,172 KB
testcase_16 AC 174 ms
78,596 KB
testcase_17 AC 161 ms
78,956 KB
testcase_18 AC 167 ms
78,436 KB
testcase_19 AC 169 ms
78,800 KB
testcase_20 AC 105 ms
76,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
N, V, x, y = map(int, input().split())
O = (x - 1, y - 1)
G = (N - 1, N - 1)
L = [list(map(int, input().split())) for i in range(N)]
dxy = ((1, 0), (0, 1), (-1, 0), (0, -1))
D = [[0] * N for i in range(N)]
D[0][0] = -V
Q = []
heapq.heappush(Q, (-V, (0, 0), True))
while Q:
    v, h, f = heapq.heappop(Q)
    if h == G:
        print("YES")
        break
    for dx, dy in dxy:
        nx = h[0] + dx
        ny = h[1] + dy
        if 0 <= nx < N and 0 <= ny < N:
            n = (nx, ny)
            nv = v + L[ny][nx]
            if f and n == O:
                nv *= 2
                f = False
            if nv < D[ny][nx]:
                D[ny][nx] = nv
                heapq.heappush(Q, (nv, n, f))
else:
    print("NO")
0