結果

問題 No.20 砂漠のオアシス
ユーザー mkawa2mkawa2
提出日時 2020-01-03 22:43:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,620 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2024-05-02 07:40:31
合計ジャッジ時間 2,237 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 27 ms
10,880 KB
testcase_02 AC 28 ms
10,880 KB
testcase_03 AC 33 ms
10,880 KB
testcase_04 WA -
testcase_05 AC 161 ms
14,976 KB
testcase_06 AC 52 ms
11,904 KB
testcase_07 AC 237 ms
13,056 KB
testcase_08 AC 86 ms
11,648 KB
testcase_09 AC 208 ms
12,416 KB
testcase_10 AC 29 ms
11,008 KB
testcase_11 AC 27 ms
10,880 KB
testcase_12 AC 34 ms
11,008 KB
testcase_13 AC 32 ms
11,008 KB
testcase_14 AC 48 ms
11,136 KB
testcase_15 AC 44 ms
11,136 KB
testcase_16 AC 73 ms
11,264 KB
testcase_17 AC 54 ms
11,008 KB
testcase_18 AC 60 ms
11,008 KB
testcase_19 AC 69 ms
11,264 KB
testcase_20 AC 31 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n, v, oj, oi = MI()
    oi, oj = oi - 1, oj - 1
    ll = [LI() for _ in range(n)]

    dp0 = [[0] * n for _ in range(n)]
    hp=[]
    heappush(hp,[-v,0,0])
    while hp:
        p,i,j=heappop(hp)
        p=-p
        if p<=dp0[i][j]:continue
        dp0[i][j]=p
        if (i,j)==(oi,oj):continue
        for di,dj in [(1,0),(0,1),(-1,0),(0,-1)]:
            ni,nj=i+di,j+dj
            if ni<0 or ni>=n or nj<0 or nj>=n:continue
            np=p-ll[ni][nj]
            if np<=dp0[ni][nj]:continue
            if (ni,nj)==(n-1,n-1):
                p2D(dp0)
                print("YES")
                exit()
            heappush(hp,[-np,ni,nj])

    if dp0[oi][oj]==0:
        print("NO")
        exit()

    dp1 = [[0] * n for _ in range(n)]
    hp=[]
    heappush(hp,[-dp0[oi][oj]*2,oi,oj])
    while hp:
        p,i,j=heappop(hp)
        p=-p
        if p<=dp1[i][j]:continue
        dp1[i][j]=p
        for di,dj in [(1,0),(0,1),(-1,0),(0,-1)]:
            ni,nj=i+di,j+dj
            if ni<0 or ni>=n or nj<0 or nj>=n:continue
            np=p-ll[ni][nj]
            if np<=dp1[ni][nj]:continue
            if (ni,nj)==(n-1,n-1):
                print("YES")
                exit()
            heappush(hp,[-np,ni,nj])
    print("NO")

main()
0