結果

問題 No.20 砂漠のオアシス
ユーザー szkhtsszkhts
提出日時 2021-04-22 11:01:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 11,328 KB
最終ジャッジ日時 2023-09-17 09:55:31
合計ジャッジ時間 2,812 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

def dijkstra(y, x):
    dp = [[float('inf')] * N for _ in range(N)]
    dp[0][0] = 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")
    exit()
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