結果

問題 No.20 砂漠のオアシス
ユーザー titiatitia
提出日時 2021-11-07 01:42:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 275 ms / 5,000 ms
コード長 1,017 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-25 14:37:43
合計ジャッジ時間 2,697 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,136 KB
testcase_01 AC 32 ms
11,136 KB
testcase_02 AC 32 ms
11,136 KB
testcase_03 AC 37 ms
11,136 KB
testcase_04 AC 48 ms
11,136 KB
testcase_05 AC 226 ms
13,056 KB
testcase_06 AC 63 ms
11,904 KB
testcase_07 AC 275 ms
13,184 KB
testcase_08 AC 99 ms
11,904 KB
testcase_09 AC 249 ms
12,416 KB
testcase_10 AC 30 ms
11,008 KB
testcase_11 AC 31 ms
11,008 KB
testcase_12 AC 42 ms
11,136 KB
testcase_13 AC 40 ms
11,008 KB
testcase_14 AC 57 ms
11,136 KB
testcase_15 AC 50 ms
11,008 KB
testcase_16 AC 84 ms
11,264 KB
testcase_17 AC 67 ms
11,008 KB
testcase_18 AC 75 ms
11,136 KB
testcase_19 AC 81 ms
11,136 KB
testcase_20 AC 35 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

N,V,cx,cy=map(int,input().split())
MAP=[list(map(int,input().split())) for i in range(N)]

cx-=1
cy-=1

DP1=[[0]*N for i in range(N)]
DP2=[[0]*N for i in range(N)]

DP1[0][0]=V

Q=[(-V,0,0,1)]

while Q:
    hp,x,y,c=heapq.heappop(Q)
    hp=-hp

    if c==1:
        for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
            if 0<=z<N and 0<=w<N:
                if DP1[z][w]<hp-MAP[z][w]:
                    DP1[z][w]=hp-MAP[z][w]
                    heapq.heappush(Q,(-DP1[z][w],z,w,1))

                    if z==cy and w==cx and DP2[z][w]<(hp-MAP[z][w])*2:
                        DP2[z][w]=(hp-MAP[z][w])*2
                        heapq.heappush(Q,(-DP2[z][w],z,w,2))

    else:
        for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
            if 0<=z<N and 0<=w<N:
                if DP2[z][w]<hp-MAP[z][w]:
                    DP2[z][w]=hp-MAP[z][w]
                    heapq.heappush(Q,(-DP2[z][w],z,w,2))

if DP1[N-1][N-1]>0 or DP2[N-1][N-1]>0:
    print("YES")
else:
    print("NO")
        
0