結果

問題 No.20 砂漠のオアシス
ユーザー kohei2019kohei2019
提出日時 2021-02-10 10:12:32
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,787 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 84,028 KB
最終ジャッジ日時 2023-09-22 03:21:37
合計ジャッジ時間 5,046 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,416 KB
testcase_01 AC 84 ms
71,216 KB
testcase_02 AC 84 ms
71,332 KB
testcase_03 AC 143 ms
77,916 KB
testcase_04 AC 143 ms
78,004 KB
testcase_05 AC 376 ms
84,028 KB
testcase_06 AC 199 ms
80,808 KB
testcase_07 AC 303 ms
82,332 KB
testcase_08 AC 182 ms
80,476 KB
testcase_09 AC 277 ms
81,036 KB
testcase_10 WA -
testcase_11 AC 83 ms
71,076 KB
testcase_12 WA -
testcase_13 AC 156 ms
78,772 KB
testcase_14 AC 196 ms
79,992 KB
testcase_15 AC 173 ms
79,124 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 202 ms
79,600 KB
testcase_20 AC 143 ms
77,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
#ダイクストラ法
N,V,ox,oy = map(int,input().split())
ox -= 1
oy -= 1
lsL = [list(map(int,input().split())) for i in range(N)]
dxy =[(1,0),(0,1),(-1,0),(0,-1)]
#オアシスを通らない場合
lsHP = [[-float('INF')]*(N) for i in range(N)]
lsHP[0][0] = V
used = [[False]*(N) for i in range(N)]
h = [(-V,0,0)]
heapq.heapify(h)
while h:
    cost,x,y = heapq.heappop(h)
    if used[x][y]:
        continue
    used[x][y] = True
    for dx,dy in dxy:
        if 0<=x+dx<N and 0<=y+dy<N:
            if used[x+dx][y+dy]:
                continue
            if (lsHP[x][y] - lsL[x+dx][y+dy]) < 0:
                continue
            if lsHP[x+dx][y+dy] < (lsHP[x][y] - lsL[x+dx][y+dy]):
                lsHP[x+dx][y+dy] = (lsHP[x][y] - lsL[x+dx][y+dy])
                heapq.heappush(h,(-lsHP[x+dx][y+dy],x+dx,y+dy))
if lsHP[-1][-1] > 0:
    print('YES')
    sys.exit()
if ox != -1 and oy != -1:
    #オアシスを通る場合
    lsHP2 = [[-float('INF')]*(N) for i in range(N)]
    lsHP2[ox][oy] = lsHP[ox][oy]*2
    used = [[False]*(N) for i in range(N)]
    h = [(-lsHP[ox][oy],ox,oy)]
    heapq.heapify(h)
    while h:
        cost,x,y = heapq.heappop(h)
        if used[x][y]:
            continue
        used[x][y] = True
        for dx,dy in dxy:
            if 0<=x+dx<N and 0<=y+dy<N:
                if used[x+dx][y+dy]:
                    continue
                if (lsHP2[x][y] - lsL[x+dx][y+dy]) < 0:
                    continue
                if lsHP2[x+dx][y+dy] < (lsHP2[x][y] - lsL[x+dx][y+dy]):
                    lsHP2[x+dx][y+dy] = (lsHP2[x][y] - lsL[x+dx][y+dy])
                    heapq.heappush(h,(-lsHP2[x+dx][y+dy],x+dx,y+dy))
    if lsHP2[-1][-1] > 0:
        print('YES')
    else:
        print('NO')
else:
    print('NO')
0