結果

問題 No.2999 Long Long Friedrice
ユーザー Theta
提出日時 2025-02-12 14:11:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 68,680 KB
最終ジャッジ日時 2025-02-12 14:11:20
合計ジャッジ時間 4,414 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque
from math import inf


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    graph = defaultdict(set)
    for a, b in zip(A, B):
        graph[a].add(a+b)

    q = deque([1])
    dists = defaultdict(lambda: inf)
    dists[1] = 0
    ans = 1
    while q:
        cur = q.popleft()
        for n in graph[cur]:
            if dists[n] > dists[cur] + 1:
                dists[n] = dists[cur] + 1
                q.append(n)
                ans = max(ans, n)
    print(ans)


if __name__ == "__main__":
    main()
0