結果

問題 No.20 砂漠のオアシス
ユーザー amyuamyu
提出日時 2019-05-03 18:21:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 336 ms / 5,000 ms
コード長 1,562 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 11,228 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2023-08-30 05:49:37
合計ジャッジ時間 3,216 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,616 KB
testcase_01 AC 19 ms
8,296 KB
testcase_02 AC 17 ms
8,588 KB
testcase_03 AC 26 ms
8,636 KB
testcase_04 AC 27 ms
8,560 KB
testcase_05 AC 284 ms
11,264 KB
testcase_06 AC 336 ms
10,624 KB
testcase_07 AC 331 ms
10,584 KB
testcase_08 AC 175 ms
10,232 KB
testcase_09 AC 319 ms
10,624 KB
testcase_10 AC 19 ms
8,236 KB
testcase_11 AC 17 ms
8,244 KB
testcase_12 AC 29 ms
8,356 KB
testcase_13 AC 29 ms
8,360 KB
testcase_14 AC 41 ms
8,292 KB
testcase_15 AC 36 ms
8,412 KB
testcase_16 AC 71 ms
8,692 KB
testcase_17 AC 58 ms
8,652 KB
testcase_18 AC 59 ms
8,792 KB
testcase_19 AC 70 ms
8,808 KB
testcase_20 AC 22 ms
8,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop, heapify
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 mc[N-1][N-1]==-1 or mc[oy-1][ox-1]==-1:
    n=heappop(a)
    nc=n[0]
    ny=n[1]
    nx=n[2]
    if(mc[ny][nx]==-1):
        mc[ny][nx]=nc
    else:
        continue
    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()
v=(v-mc[oy-1][ox-1])*2
mc=[[-1 for i in range(N)] for j in range(N)]
a=[(0,oy-1,ox-1)]
heapify(a)
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
    else:
        continue
    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