結果

問題 No.20 砂漠のオアシス
ユーザー convexineqconvexineq
提出日時 2021-01-17 02:22:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 702 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 80,768 KB
最終ジャッジ日時 2024-05-06 13:57:54
合計ジャッジ時間 3,310 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,608 KB
testcase_01 AC 41 ms
53,376 KB
testcase_02 AC 42 ms
52,992 KB
testcase_03 WA -
testcase_04 AC 85 ms
74,624 KB
testcase_05 AC 264 ms
80,768 KB
testcase_06 AC 206 ms
77,440 KB
testcase_07 AC 190 ms
77,568 KB
testcase_08 AC 186 ms
77,184 KB
testcase_09 AC 183 ms
77,184 KB
testcase_10 AC 40 ms
52,736 KB
testcase_11 AC 40 ms
52,608 KB
testcase_12 AC 83 ms
74,112 KB
testcase_13 AC 103 ms
76,416 KB
testcase_14 AC 108 ms
76,800 KB
testcase_15 AC 89 ms
76,544 KB
testcase_16 AC 106 ms
76,544 KB
testcase_17 AC 97 ms
76,416 KB
testcase_18 WA -
testcase_19 AC 110 ms
76,160 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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] and (v - d[0][0] - b[sx][sy])*2 > d[-1][-1]

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