結果

問題 No.20 砂漠のオアシス
ユーザー amyuamyu
提出日時 2019-05-03 18:12:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,508 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 11,056 KB
実行使用メモリ 22,160 KB
最終ジャッジ日時 2023-08-30 05:49:11
合計ジャッジ時間 15,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,388 KB
testcase_01 AC 19 ms
8,576 KB
testcase_02 WA -
testcase_03 AC 2,429 ms
22,160 KB
testcase_04 AC 142 ms
9,404 KB
testcase_05 AC 84 ms
11,028 KB
testcase_06 WA -
testcase_07 AC 88 ms
9,308 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 18 ms
8,456 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 273 ms
10,128 KB
testcase_15 AC 364 ms
10,692 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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 and 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
    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
    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