結果

問題 No.1244 Black Segment
ユーザー 👑 rin204rin204
提出日時 2022-07-06 06:55:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 668 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 86,340 KB
実行使用メモリ 90,172 KB
最終ジャッジ日時 2023-08-22 22:13:34
合計ジャッジ時間 8,756 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,592 KB
testcase_01 AC 98 ms
71,324 KB
testcase_02 AC 94 ms
71,340 KB
testcase_03 AC 93 ms
71,400 KB
testcase_04 AC 95 ms
71,320 KB
testcase_05 AC 95 ms
71,452 KB
testcase_06 AC 95 ms
71,572 KB
testcase_07 AC 99 ms
71,608 KB
testcase_08 AC 96 ms
71,284 KB
testcase_09 AC 97 ms
71,332 KB
testcase_10 AC 95 ms
71,540 KB
testcase_11 AC 95 ms
71,296 KB
testcase_12 AC 94 ms
71,392 KB
testcase_13 AC 133 ms
77,840 KB
testcase_14 AC 197 ms
79,744 KB
testcase_15 AC 134 ms
78,004 KB
testcase_16 AC 181 ms
78,608 KB
testcase_17 AC 127 ms
78,200 KB
testcase_18 AC 106 ms
76,528 KB
testcase_19 AC 104 ms
76,388 KB
testcase_20 AC 231 ms
84,204 KB
testcase_21 AC 212 ms
84,468 KB
testcase_22 AC 234 ms
84,156 KB
testcase_23 AC 255 ms
85,684 KB
testcase_24 AC 254 ms
85,444 KB
testcase_25 AC 221 ms
83,592 KB
testcase_26 AC 235 ms
86,540 KB
testcase_27 AC 259 ms
90,172 KB
testcase_28 AC 255 ms
85,896 KB
testcase_29 AC 262 ms
87,780 KB
testcase_30 AC 243 ms
84,240 KB
testcase_31 AC 261 ms
86,908 KB
testcase_32 AC 261 ms
87,212 KB
testcase_33 AC 259 ms
86,456 KB
testcase_34 AC 97 ms
71,428 KB
testcase_35 AC 162 ms
77,456 KB
testcase_36 AC 204 ms
81,804 KB
testcase_37 AC 245 ms
84,700 KB
testcase_38 AC 104 ms
76,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n, m, a, b = map(int, input().split())
n = b - a + 2
edges = [[] for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    if l <= a and b <= r:
        print(1)
        exit()
    elif r < a or b < l:
        pass
    else:
        l = max(l, a) - a
        r = min(r, b) - a + 1
        edges[l].append(r)
        edges[r].append(l)
        
        
queue = deque()
queue.append(0)
dist = [-1] * n
dist[0] = 0
while queue:
    pos = queue.popleft()
    for npos in edges[pos]:
        if dist[npos] != -1:
            continue
        dist[npos] = dist[pos] + 1
        queue.append(npos)
print(dist[-1])
        
0