結果

問題 No.20 砂漠のオアシス
ユーザー 👑 H20H20
提出日時 2021-12-21 15:12:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 683 ms / 5,000 ms
コード長 1,542 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 124,192 KB
最終ジャッジ日時 2023-10-13 19:49:46
合計ジャッジ時間 8,901 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,536 KB
testcase_01 AC 102 ms
71,964 KB
testcase_02 AC 102 ms
72,004 KB
testcase_03 AC 211 ms
81,388 KB
testcase_04 AC 272 ms
82,944 KB
testcase_05 AC 610 ms
116,876 KB
testcase_06 AC 654 ms
121,780 KB
testcase_07 AC 679 ms
122,648 KB
testcase_08 AC 683 ms
124,192 KB
testcase_09 AC 662 ms
123,152 KB
testcase_10 AC 96 ms
71,608 KB
testcase_11 AC 97 ms
71,524 KB
testcase_12 AC 240 ms
82,328 KB
testcase_13 AC 228 ms
81,192 KB
testcase_14 AC 288 ms
83,856 KB
testcase_15 AC 264 ms
82,556 KB
testcase_16 AC 362 ms
89,296 KB
testcase_17 AC 308 ms
85,740 KB
testcase_18 AC 324 ms
86,996 KB
testcase_19 AC 341 ms
87,976 KB
testcase_20 AC 186 ms
79,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import heapq


class Dijkstra:
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d):
        self.e[u].append([v, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def search(self, s):
        """
        :param s: 始点
        :return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

N,V,X,Y = map(int,input().split())
L = []
X,Y=X-1,Y-1
for _ in range(N):
    L.append(list(map(int,input().split())))
graph = Dijkstra()

for i in range(N):
    for j in range(N-1):
        graph.add((i,j),(i,j+1),L[i][j+1])
        graph.add((i,j+1),(i,j),L[i][j])

for i in range(N-1):
    for j in range(N):
        graph.add((i,j),(i+1,j),L[i+1][j])
        graph.add((i+1,j),(i,j),L[i][j])
G = graph.search((0,0))
GO = graph.search((Y,X))
if G[(N-1,N-1)]<V or G[(Y,X)]+GO[(N-1,N-1)]<V+(V-G[(Y,X)]):
    print('YES')
else:
    print('NO')
0