結果

問題 No.20 砂漠のオアシス
ユーザー rlangevinrlangevin
提出日時 2023-06-29 22:54:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,494 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 90,036 KB
最終ジャッジ日時 2023-09-20 17:55:45
合計ジャッジ時間 5,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,008 KB
testcase_01 AC 81 ms
71,308 KB
testcase_02 AC 82 ms
71,476 KB
testcase_03 AC 214 ms
79,068 KB
testcase_04 AC 137 ms
78,512 KB
testcase_05 AC 235 ms
87,960 KB
testcase_06 AC 247 ms
89,876 KB
testcase_07 AC 253 ms
90,036 KB
testcase_08 AC 262 ms
89,460 KB
testcase_09 AC 254 ms
89,816 KB
testcase_10 WA -
testcase_11 AC 83 ms
71,104 KB
testcase_12 WA -
testcase_13 AC 162 ms
79,648 KB
testcase_14 AC 178 ms
79,564 KB
testcase_15 AC 170 ms
79,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 181 ms
81,220 KB
testcase_20 AC 139 ms
78,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
inf = float('inf')


def dijkstra(s, g, N):
    # ゴールがない場合はg=-1とする。

    def cost(v, m):
        return v * N + m

    dist = [inf] * N
    mindist = [inf] * N
    seen = [False] * N
    Q = [cost(0, s)]
    while Q:
        c, m = divmod(heappop(Q), N)
        if seen[m]:
            continue
        seen[m] = True
        dist[m] = c
        if m == g:
            return dist

        #------heapをアップデートする。--------
        for u, C in G[m]:
            if seen[u]:
                continue
            newdist = dist[m] + C

            #------------------------------------
            if newdist >= mindist[u]:
                continue
            mindist[u] = newdist
            heappush(Q, cost(newdist, u))
            
    return dist


N, V, qx, qy = map(int, input().split())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
    
G = [[] for i in range(N * N)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(N):
    for j in range(N):
        for k in range(4):
            x = i + dx[k]
            y = j + dy[k]
            if x < 0 or x > N - 1 or y < 0 or y > N - 1:
                continue
            G[i * N + j].append((x * N + y, L[x][y]))
            
D = dijkstra(0, -1, N * N)
if D[-1] < V:
    print("YES")
    exit()

qx, qy = qx - 1, qy - 1    
V -= D[qx * N + qy]
V *= 2
D2 = dijkstra(qx * N + qy, -1, N * N)
print("YES") if D2[-1] < V else print("NO")
0