結果

問題 No.20 砂漠のオアシス
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-10-11 04:09:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 90,508 KB
最終ジャッジ日時 2023-09-07 06:33:29
合計ジャッジ時間 6,929 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
73,100 KB
testcase_01 AC 104 ms
72,876 KB
testcase_02 AC 104 ms
72,760 KB
testcase_03 AC 172 ms
81,008 KB
testcase_04 AC 169 ms
80,904 KB
testcase_05 AC 237 ms
88,920 KB
testcase_06 AC 322 ms
90,508 KB
testcase_07 AC 326 ms
90,148 KB
testcase_08 AC 237 ms
89,984 KB
testcase_09 AC 312 ms
90,380 KB
testcase_10 WA -
testcase_11 AC 104 ms
72,628 KB
testcase_12 WA -
testcase_13 AC 190 ms
81,416 KB
testcase_14 AC 208 ms
82,632 KB
testcase_15 AC 197 ms
82,180 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 230 ms
83,152 KB
testcase_20 AC 169 ms
80,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N,V,X,Y = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(N)]

M = N**2
e = [[] for _ in range(M)]

def f(i,j):
    
    return N*i+j

H = N
W = N
def nb(x,y):
    tmp = []
    if x+1<H:
        tmp.append((x+1,y))
    if x-1>=0:
        tmp.append((x-1,y))
    if y+1<W:
        tmp.append((x,y+1))
    if y-1>=0:
        tmp.append((x,y-1))
    return tmp
    
X -= 1
Y -= 1

for i in range(N):
    for j in range(N):
        
        x = f(i,j)
        
        for ix,iy in nb(i,j):
            
            e[x].append((f(ix,iy),L[ix][iy]))
            
INF = (1<<30)
def dijkstra(s,e):
    
    N = len(e)
    dist = [INF]*N
    dist[s]=0
    h = []
    heappush(h,(0,s))
    while h:
        nw,v = heappop(h)
        if dist[v]!=nw:
            continue
        for iv,ic in e[v]:
            nc = ic + nw
            if nc < dist[iv]:
                dist[iv] = nc
                heappush(h,(nc,iv))
    return dist



D = dijkstra(0,e)
if D[-1]<=V:
    print('YES')
    exit()
    
oasis = f(X,Y)
if D[oasis]>V:
    print('NO')
    exit()

H = V - D[oasis]
H *=2
D =dijkstra(oasis,e)
if D[-1]<=H:
    print('YES')
else:
    print('NO')
0