結果

問題 No.20 砂漠のオアシス
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-12-31 09:52:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 86,656 KB
最終ジャッジ日時 2024-04-16 20:38:36
合計ジャッジ時間 3,336 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
53,632 KB
testcase_01 AC 56 ms
61,696 KB
testcase_02 AC 56 ms
61,184 KB
testcase_03 AC 72 ms
68,480 KB
testcase_04 AC 87 ms
73,984 KB
testcase_05 AC 253 ms
85,504 KB
testcase_06 AC 258 ms
85,760 KB
testcase_07 AC 245 ms
86,656 KB
testcase_08 AC 221 ms
84,352 KB
testcase_09 AC 214 ms
82,944 KB
testcase_10 AC 47 ms
53,504 KB
testcase_11 AC 48 ms
53,760 KB
testcase_12 AC 80 ms
70,016 KB
testcase_13 AC 80 ms
70,912 KB
testcase_14 AC 92 ms
76,928 KB
testcase_15 AC 82 ms
72,064 KB
testcase_16 AC 102 ms
76,672 KB
testcase_17 AC 95 ms
76,800 KB
testcase_18 AC 103 ms
76,672 KB
testcase_19 AC 102 ms
76,672 KB
testcase_20 AC 74 ms
67,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,v,y,x = 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 x > 0 and diso[-1][-1] < (v-dis0[x-1][y-1])*2:
    ans = "YES" 
print(ans) 
0