結果

問題 No.20 砂漠のオアシス
ユーザー convexineqconvexineq
提出日時 2021-01-17 02:33:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 725 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 80,400 KB
最終ジャッジ日時 2024-05-06 14:07:17
合計ジャッジ時間 3,468 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,352 KB
testcase_01 AC 41 ms
53,248 KB
testcase_02 AC 46 ms
52,864 KB
testcase_03 AC 82 ms
74,112 KB
testcase_04 AC 81 ms
74,880 KB
testcase_05 AC 270 ms
80,400 KB
testcase_06 AC 196 ms
77,516 KB
testcase_07 AC 195 ms
77,544 KB
testcase_08 AC 195 ms
77,568 KB
testcase_09 AC 200 ms
77,312 KB
testcase_10 AC 44 ms
52,736 KB
testcase_11 AC 39 ms
52,736 KB
testcase_12 AC 76 ms
74,624 KB
testcase_13 AC 91 ms
76,672 KB
testcase_14 AC 95 ms
76,416 KB
testcase_15 AC 88 ms
76,416 KB
testcase_16 AC 106 ms
76,416 KB
testcase_17 AC 103 ms
76,416 KB
testcase_18 AC 109 ms
76,716 KB
testcase_19 AC 105 ms
76,672 KB
testcase_20 AC 74 ms
71,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,v,sy,sx = map(int,input().split())
b = [list(map(int,input().split())) for _ in range(n)]
sx -= 1;sy -= 1

def dijkstra(x,y,flag):
    d = [[-1]*n for _ in range(n)]
    d[x][y] = 0
    from heapq import heappush, heappop
    q = [(0,x,y)]
    while q:
        dv,x,y = heappop(q)
        for nx,ny in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
            if 0 <= nx < n and 0 <= ny < n and d[nx][ny]==-1:
                d[nx][ny] = dv + b[nx][ny]
                heappush(q,(dv + b[nx][ny],nx,ny))
    if flag:
        return v > d[-1][-1]
    else:
        return v > d[0][0] + b[sx][sy] - b[0][0] and (v - d[0][0] - b[sx][sy] + b[0][0])*2 > d[-1][-1]

print("YES" if dijkstra(0,0,1) or (sx>=0 and dijkstra(sx,sy,0)) else "NO")
0