結果

問題 No.3797 Express Elevators and Emergency Stairs
コンテスト
ユーザー LyricalMaestro
提出日時 2026-11-15 03:42:19
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 553 ms / 2,000 ms
+ 650µs
コード長 1,024 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 90 ms
コンパイル使用メモリ 64,488 KB
実行使用メモリ 146,116 KB
最終ジャッジ日時 2026-11-15 03:42:26
合計ジャッジ時間 6,583 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://yukicoder.me/problems/no/3797

from collections import deque

def main():
    N = int(input())
    ab = []
    for _ in range(N):
        a, b = map(int, input().split())
        ab.append((a, b))

    # 座標圧縮
    a_set = {1}
    for a, b in ab:
        a_set.add(a)
        a_set.add(b)
    a_list = list(a_set)
    a_list.sort()
    a_map = {}
    for i , a in enumerate(a_list):
        a_map[a] = i
    a_max = len(a_list)

    next_nodes = [[] for _ in range(a_max)]
    for a, b in ab:
        next_nodes[a_map[a]].append(a_map[b])
    for i in range(1, a_max):
        next_nodes[i].append(i - 1)

    dp = [False] * a_max
    dp[0] = True

    queue = deque()
    queue.append(0)
    while len(queue) > 0:
        v = queue.popleft()
        for w in next_nodes[v]:
            if not dp[w]:
                dp[w] = True
                queue.append(w)

    for i in reversed(range(a_max)):
        if dp[i]:
            print(a_list[i])
            return





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