結果

問題 No.20 砂漠のオアシス
ユーザー kohei2019kohei2019
提出日時 2021-02-10 10:11:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,787 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 84,220 KB
最終ジャッジ日時 2023-09-22 03:20:18
合計ジャッジ時間 6,087 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,108 KB
testcase_01 AC 83 ms
71,268 KB
testcase_02 WA -
testcase_03 AC 161 ms
77,968 KB
testcase_04 AC 149 ms
78,000 KB
testcase_05 AC 398 ms
84,220 KB
testcase_06 WA -
testcase_07 AC 320 ms
82,044 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 86 ms
71,284 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 209 ms
80,156 KB
testcase_15 AC 182 ms
78,988 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 147 ms
77,612 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