結果

問題 No.20 砂漠のオアシス
ユーザー szkhtsszkhts
提出日時 2022-11-13 08:48:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 959 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 11,104 KB
実行使用メモリ 11,344 KB
最終ジャッジ日時 2023-10-12 19:01:35
合計ジャッジ時間 2,359 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,312 KB
testcase_01 AC 16 ms
8,416 KB
testcase_02 AC 17 ms
8,428 KB
testcase_03 AC 22 ms
8,320 KB
testcase_04 AC 26 ms
8,488 KB
testcase_05 AC 147 ms
10,216 KB
testcase_06 AC 156 ms
11,196 KB
testcase_07 AC 158 ms
11,180 KB
testcase_08 AC 155 ms
11,140 KB
testcase_09 AC 156 ms
11,344 KB
testcase_10 AC 17 ms
8,428 KB
testcase_11 AC 16 ms
8,260 KB
testcase_12 AC 21 ms
8,432 KB
testcase_13 AC 22 ms
8,480 KB
testcase_14 AC 27 ms
8,412 KB
testcase_15 AC 25 ms
8,496 KB
testcase_16 AC 42 ms
8,580 KB
testcase_17 AC 34 ms
8,652 KB
testcase_18 AC 38 ms
8,504 KB
testcase_19 AC 43 ms
8,540 KB
testcase_20 AC 19 ms
8,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappush, heappop

def dijkstra(y, x):
    dp = [[float('inf')] * N for _ in range(N)]
    dp[y][x] = 0
    hq = [(0, y, x)]
    while(hq):
        h, sy, sx = heappop(hq)
        if dp[sy][sx] < h:
            continue
        for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            ny = sy + dy
            nx = sx + dx
            if 0 <= ny < N and 0 <= nx < N and dp[ny][nx] > h + sand_area[ny][nx]:
                dp[ny][nx] = h + sand_area[ny][nx]
                heappush(hq, (h + sand_area[ny][nx], ny, nx))
    return dp

N, V, Ox, Oy = map(int, input().split())
Ox -= 1
Oy -= 1
sand_area = [list(map(int, input().split())) for _ in range(N)]
dp1 = dijkstra(0, 0)
if Ox == Oy == -1:
    if dp1[N - 1][N - 1] < V:
        print("YES")
    else:
        print("NO")
    sys.exit(0)
dp2 = dijkstra(Oy, Ox)
if dp1[N - 1][N - 1] < V or (V - dp1[Oy][Ox]) * 2 > dp2[N - 1][N - 1]:
    print("YES")
else:
    print("NO")
0