結果

問題 No.1465 Archaea
ユーザー gorugo30gorugo30
提出日時 2021-04-02 21:33:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 394 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 116,768 KB
最終ジャッジ日時 2023-08-25 16:09:37
合計ジャッジ時間 5,859 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,420 KB
testcase_01 AC 77 ms
71,428 KB
testcase_02 AC 84 ms
75,928 KB
testcase_03 AC 76 ms
71,332 KB
testcase_04 AC 74 ms
71,368 KB
testcase_05 AC 77 ms
71,368 KB
testcase_06 AC 75 ms
71,468 KB
testcase_07 AC 195 ms
86,776 KB
testcase_08 AC 77 ms
71,632 KB
testcase_09 AC 225 ms
91,504 KB
testcase_10 AC 76 ms
71,340 KB
testcase_11 AC 209 ms
89,312 KB
testcase_12 AC 110 ms
77,944 KB
testcase_13 AC 324 ms
106,768 KB
testcase_14 AC 214 ms
89,796 KB
testcase_15 AC 101 ms
77,420 KB
testcase_16 AC 116 ms
78,132 KB
testcase_17 AC 337 ms
108,204 KB
testcase_18 AC 150 ms
80,528 KB
testcase_19 AC 222 ms
91,080 KB
testcase_20 AC 282 ms
100,488 KB
testcase_21 AC 383 ms
116,768 KB
testcase_22 AC 394 ms
116,748 KB
testcase_23 AC 76 ms
71,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

class Dijkstra:
    def __init__(self, V, INF = 10 ** 20):
        self.V = V
        self.INF = INF
        self.dist = None
        self.prev = None
        self.adj = [[] for _ in range(V)]
    def add(self, u, v, dist):
        self.adj[u].append((v, dist))
    def run(self, start):
        self.dist = [self.INF] * self.V
        self.prev = [-1] * self.V
        self.dist[start] = 0
        priq = [(0, start)]
        while len(priq):
            d, v = heapq.heappop(priq)
            if self.dist[v] < d:
                continue
            for to, cost in self.adj[v]:
                dd = d + cost
                if self.dist[to] > dd:
                    self.dist[to] = dd
                    self.prev[to] = v
                    heapq.heappush(priq, (dd, to))

N, K = map(int, input().split())
dij = Dijkstra(N + 1)
for i in range(1, N + 1):
    if i * 2 <= N:
        dij.add(i, 2 * i, 1)
    if i + 3 <= N:
        dij.add(i, i + 3, 1)
dij.run(1)

if dij.dist[N] <= K:
    print("YES")
else:
    print("NO")
0