結果

問題 No.20 砂漠のオアシス
ユーザー convexineqconvexineq
提出日時 2021-01-17 02:30:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 76,156 KB
最終ジャッジ日時 2023-08-19 06:51:12
合計ジャッジ時間 3,281 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,208 KB
testcase_01 AC 66 ms
71,220 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 69 ms
75,548 KB
testcase_05 AC 75 ms
75,732 KB
testcase_06 WA -
testcase_07 AC 72 ms
75,540 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 70 ms
70,888 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 69 ms
75,728 KB
testcase_15 AC 72 ms
75,400 KB
testcase_16 AC 71 ms
75,420 KB
testcase_17 WA -
testcase_18 AC 74 ms
75,600 KB
testcase_19 WA -
testcase_20 AC 66 ms
71,356 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)
        if d[x][y] <= dv: continue
        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