結果

問題 No.20 砂漠のオアシス
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-10-11 04:18:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 322 ms / 5,000 ms
コード長 1,427 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 90,624 KB
最終ジャッジ日時 2023-09-07 06:40:12
合計ジャッジ時間 5,814 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
72,832 KB
testcase_01 AC 108 ms
72,588 KB
testcase_02 AC 111 ms
72,800 KB
testcase_03 AC 169 ms
80,868 KB
testcase_04 AC 167 ms
80,896 KB
testcase_05 AC 306 ms
90,044 KB
testcase_06 AC 319 ms
90,624 KB
testcase_07 AC 322 ms
90,480 KB
testcase_08 AC 239 ms
89,976 KB
testcase_09 AC 308 ms
90,448 KB
testcase_10 AC 104 ms
72,768 KB
testcase_11 AC 106 ms
72,700 KB
testcase_12 AC 186 ms
81,312 KB
testcase_13 AC 192 ms
81,860 KB
testcase_14 AC 212 ms
82,804 KB
testcase_15 AC 194 ms
82,124 KB
testcase_16 AC 243 ms
83,156 KB
testcase_17 AC 230 ms
83,172 KB
testcase_18 AC 224 ms
83,148 KB
testcase_19 AC 242 ms
83,820 KB
testcase_20 AC 167 ms
80,324 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
X,Y = Y,X
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 (X,Y)==(-1,-1):
    if D[-1]<V:
        print('YES')
    else:
        print('NO')
    exit()
           
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