結果

問題 No.1995 CHIKA Road
ユーザー LyricalMaestro
提出日時 2025-09-13 10:09:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 82,660 KB
実行使用メモリ 154,940 KB
最終ジャッジ日時 2025-09-13 10:09:30
合計ジャッジ時間 8,408 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import math

def main():
    N, M = map(int, input().split())
    ab = []
    b_map = {}
    for _ in range(M):
        a, b = map(int ,input().split())
        ab.append((a ,b))
        b_map[b] = a
    
    pos_set = set()
    for a, b in ab:
        pos_set.add(a)
        pos_set.add(b)
    pos_set.add(1)
    pos_set.add(N)
    pos_list = list(pos_set)
    pos_list.sort()

    answer = 0
    dp = {1: 0}
    for i in range(len(pos_list)):
        p = pos_list[i]

        ans = answer
        if p in b_map:
            ans = max(ans, dp[b_map[p]] + 1)
        dp[p] = ans
        answer = ans
    
    x = dp[N]
    answer = 2 * (N - 1) - x
    print(answer)








    



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