結果

問題 No.20 砂漠のオアシス
ユーザー aaaaaaaaaa2230
提出日時 2021-12-31 09:49:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 86,020 KB
最終ジャッジ日時 2024-10-07 23:39:15
合計ジャッジ時間 3,698 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,v,x,y = map(int,input().split())
L = [list(map(int,input().split())) for i in range(n)]
inf = 10**10

def bfs(sx,sy):
    dis = [[inf]*n for i in range(n)]
    dis[sx][sy] = 0
    q = deque([[sx,sy]])
    while q:
        nx,ny = q.popleft()
        for (i,j) in ((1,0),(-1,0),(0,1),(0,-1)):
            nnx = nx+i
            nny = ny+j
            if 0 <= nnx < n and 0 <= nny < n and dis[nnx][nny] > dis[nx][ny]+L[nnx][nny]:
                dis[nnx][nny] = dis[nx][ny]+L[nnx][nny]
                q.append([nnx,nny])
    return dis


dis0 = bfs(0,0)
diso = bfs(x-1,y-1)
ans = "NO"
if dis0[-1][-1] < v:
    ans = "YES"

if diso[-1][-1] < (v-dis0[x-1][y-1])*2:
    ans = "YES" 
print(ans) 
0