結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,352 KB
testcase_01 AC 41 ms
53,120 KB
testcase_02 AC 43 ms
52,864 KB
testcase_03 AC 83 ms
73,984 KB
testcase_04 AC 90 ms
74,496 KB
testcase_05 AC 237 ms
80,256 KB
testcase_06 AC 186 ms
77,824 KB
testcase_07 AC 187 ms
77,312 KB
testcase_08 AC 188 ms
77,312 KB
testcase_09 AC 192 ms
77,184 KB
testcase_10 AC 38 ms
52,480 KB
testcase_11 AC 37 ms
52,480 KB
testcase_12 AC 79 ms
74,240 KB
testcase_13 AC 90 ms
76,416 KB
testcase_14 AC 96 ms
76,672 KB
testcase_15 AC 89 ms
76,288 KB
testcase_16 AC 105 ms
76,160 KB
testcase_17 AC 99 ms
76,288 KB
testcase_18 WA -
testcase_19 AC 111 ms
76,672 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>=0 and dijkstra(sx,sy,0)) else "NO")
0