結果

問題 No.20 砂漠のオアシス
ユーザー amyuamyu
提出日時 2019-05-03 18:06:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,453 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 11,104 KB
実行使用メモリ 33,916 KB
最終ジャッジ日時 2023-08-30 05:48:28
合計ジャッジ時間 10,984 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
33,916 KB
testcase_01 AC 18 ms
8,544 KB
testcase_02 AC 19 ms
8,488 KB
testcase_03 AC 2,235 ms
22,212 KB
testcase_04 AC 1,163 ms
11,428 KB
testcase_05 AC 432 ms
11,420 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
N,v,ox,oy=map(int, input().split())
l=[list(map(int, input().split())) for i in range(N)]
mc=[[-1 for i in range(N)] for j in range(N)]
a=[(0,0,0)]
heapify(a)
while len(a)>0:
    n=heappop(a)
    nc=n[0]
    ny=n[1]
    nx=n[2]
    if(mc[ny][nx]==-1):
        mc[ny][nx]=nc
    if(nx>0):
        if(mc[ny][nx-1]==-1):
            heappush(a, (nc+l[ny][nx-1],ny,nx-1))
    if(ny>0):
        if(mc[ny-1][nx]==-1):
            heappush(a, (nc+l[ny-1][nx],ny-1,nx))
    if(nx<N-1):
        if(mc[ny][nx+1]==-1):
            heappush(a, (nc+l[ny][nx+1],ny,nx+1))
    if(ny<N-1):
        if(mc[ny+1][nx]==-1):
            heappush(a, (nc+l[ny+1][nx],ny+1,nx))
if(mc[N-1][N-1]<v):
    print("YES")
    quit()
if(ox==0 and oy==0) or (mc[oy-1][ox-1]>=v):
    print("NO")
    quit()
mc=[[-1 for i in range(N)] for j in range(N)]
a=[(0,oy-1,ox-1)]
heapify(a)
v=(v-mc[oy-1][ox-1])*2
while mc[N-1][N-1]==-1:
    n=heappop(a)
    nc=n[0]
    ny=n[1]
    nx=n[2]
    if(mc[ny][nx]==-1):
        mc[ny][nx]=nc
    if(nx>0):
        if(mc[ny][nx-1]==-1):
            heappush(a, (nc+l[ny][nx-1],ny,nx-1))
    if(ny>0):
        if(mc[ny-1][nx]==-1):
            heappush(a, (nc+l[ny-1][nx],ny-1,nx))
    if(nx<N-1):
        if(mc[ny][nx+1]==-1):
            heappush(a, (nc+l[ny][nx+1],ny,nx+1))
    if(ny<N-1):
        if(mc[ny+1][nx]==-1):
            heappush(a, (nc+l[ny+1][nx],ny+1,nx))
if(mc[N-1][N-1]<v):
    print("YES")
else:
    print("NO")
0