結果

問題 No.1995 CHIKA Road
ユーザー roarisroaris
提出日時 2022-10-29 17:00:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 162,236 KB
最終ジャッジ日時 2023-09-20 20:05:56
合計ジャッジ時間 9,644 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,612 KB
testcase_01 AC 92 ms
71,528 KB
testcase_02 AC 92 ms
71,500 KB
testcase_03 AC 92 ms
71,668 KB
testcase_04 AC 92 ms
71,892 KB
testcase_05 AC 92 ms
71,512 KB
testcase_06 AC 129 ms
79,900 KB
testcase_07 AC 164 ms
89,436 KB
testcase_08 AC 94 ms
71,540 KB
testcase_09 AC 93 ms
71,664 KB
testcase_10 AC 146 ms
86,400 KB
testcase_11 AC 397 ms
147,940 KB
testcase_12 AC 252 ms
117,244 KB
testcase_13 AC 192 ms
111,368 KB
testcase_14 AC 196 ms
111,344 KB
testcase_15 AC 367 ms
162,236 KB
testcase_16 AC 140 ms
84,204 KB
testcase_17 AC 226 ms
113,216 KB
testcase_18 AC 292 ms
131,124 KB
testcase_19 AC 295 ms
131,584 KB
testcase_20 AC 210 ms
109,312 KB
testcase_21 AC 207 ms
108,376 KB
testcase_22 AC 281 ms
126,816 KB
testcase_23 AC 167 ms
89,428 KB
testcase_24 AC 270 ms
130,680 KB
testcase_25 AC 147 ms
85,280 KB
testcase_26 AC 176 ms
100,068 KB
testcase_27 AC 255 ms
126,840 KB
testcase_28 AC 202 ms
107,492 KB
testcase_29 AC 293 ms
130,876 KB
testcase_30 AC 141 ms
85,108 KB
testcase_31 AC 127 ms
79,108 KB
testcase_32 AC 151 ms
87,912 KB
testcase_33 AC 253 ms
126,892 KB
testcase_34 AC 129 ms
79,960 KB
testcase_35 AC 170 ms
96,180 KB
testcase_36 AC 185 ms
103,472 KB
testcase_37 AC 273 ms
127,412 KB
testcase_38 AC 230 ms
114,476 KB
testcase_39 AC 128 ms
79,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
G = defaultdict(list)
l = [1, N]

for _ in range(M):
    u, v = map(int, input().split())
    G[u].append(v)
    l += [u, v]

l = list(set(l))
l.sort()
idx = defaultdict(int)

for i in range(len(l)):
    idx[l[i]] = i
    
dp = [10**18]*len(l)
dp[0] = 0

for i in range(len(l)):
    if i+1<len(l):
        dp[i+1] = min(dp[i+1], dp[i]+2*(l[i+1]-l[i]))
    
    for j in G[l[i]]:
        dp[idx[j]] = min(dp[idx[j]], dp[i]+2*j-2*l[i]-1)

print(dp[-1])
0