結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-11 04:18:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 268 ms / 5,000 ms |
| コード長 | 1,427 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 87,368 KB |
| 最終ジャッジ日時 | 2024-06-25 01:01:56 |
| 合計ジャッジ時間 | 4,264 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
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')