結果

問題 No.1557 Binary Variable
ユーザー ProgrammerryokiProgrammerryoki
提出日時 2021-06-25 22:54:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 874 ms / 2,000 ms
コード長 1,978 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 13,100 KB
最終ジャッジ日時 2023-09-07 14:54:09
合計ジャッジ時間 30,105 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 862 ms
13,100 KB
testcase_01 AC 775 ms
8,260 KB
testcase_02 AC 17 ms
8,272 KB
testcase_03 AC 17 ms
8,224 KB
testcase_04 AC 851 ms
8,280 KB
testcase_05 AC 851 ms
8,208 KB
testcase_06 AC 856 ms
8,188 KB
testcase_07 AC 874 ms
8,316 KB
testcase_08 AC 853 ms
8,212 KB
testcase_09 AC 865 ms
8,280 KB
testcase_10 AC 874 ms
8,264 KB
testcase_11 AC 843 ms
8,300 KB
testcase_12 AC 853 ms
8,236 KB
testcase_13 AC 859 ms
8,208 KB
testcase_14 AC 827 ms
8,288 KB
testcase_15 AC 863 ms
8,320 KB
testcase_16 AC 815 ms
8,276 KB
testcase_17 AC 838 ms
8,208 KB
testcase_18 AC 836 ms
8,228 KB
testcase_19 AC 823 ms
8,376 KB
testcase_20 AC 832 ms
8,192 KB
testcase_21 AC 813 ms
8,208 KB
testcase_22 AC 831 ms
8,376 KB
testcase_23 AC 819 ms
8,376 KB
testcase_24 AC 820 ms
8,360 KB
testcase_25 AC 816 ms
8,212 KB
testcase_26 AC 814 ms
8,368 KB
testcase_27 AC 821 ms
8,212 KB
testcase_28 AC 827 ms
8,324 KB
testcase_29 AC 827 ms
8,324 KB
testcase_30 AC 822 ms
8,288 KB
testcase_31 AC 821 ms
8,192 KB
testcase_32 AC 801 ms
8,272 KB
testcase_33 AC 804 ms
8,216 KB
testcase_34 AC 17 ms
8,376 KB
testcase_35 AC 17 ms
8,352 KB
testcase_36 AC 17 ms
8,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

N,M = [int(i) for i in input().split()]
union = []
dic = {}
for _ in range(M):
    # print(union)
    # print(dic)
    L,R = [int(i) for i in input().split()]
    ind = bisect_left(union, L)
    if len(union) == 0:
        union.append(L)
        dic[L] = (L,R)
    if ind == 0:
        l,r = dic[union[0]]
        if R < l:
            union = [L] + union
            dic[L] = (L,R)
            continue
        n = None
        if L <= l <= R <= r:
            n = (l, R)
        elif L <= l <= r <= R:
            n = (l,r)
        union[0] = n[0]
        del dic[l]
        dic[n[0]] = n
    elif ind == len(union):
        l,r = dic[union[ind-1]]
        if r < L:
            union.append(L)
            dic[L] = (L,R)
            continue
        elif l <= L <= r <= R:
            n = (L,r)
        elif l <= L <= R <= r:
            n = (L,R)
        elif L <= l <= R <= r:
            n = (l, R)
        elif L <= l <= r <= R:
            n = (l,r)
        union[ind-1] = n[0]
        del dic[l]
        dic[n[0]] = n
    else:
        l,r = dic[union[ind-1]]
        n = None
        if r < L:
            l,r = dic[union[ind]]
            if R < l:
                union = [L] + union
                dic[L] = (L,R)
                continue
            n = None
            if l <= L <= r <= R:
                n = (L,r)
            elif l <= L <= R <= r:
                n = (L,R)
            elif L <= l <= R <= r:
                n = (l, R)
            elif L <= l <= r <= R:
                n = (l,r)
            union[ind] = n[0]
            del dic[l]
            dic[n[0]] = n
            continue
        elif l <= L <= r <= R:
            n = (L,r)
        elif l <= L <= R <= r:
            n = (L,R)
        elif L <= l <= R <= r:
            n = (l, R)
        elif L <= l <= r <= R:
            n = (l,r)
        union[ind-1] = n[0]
        del dic[l]
        dic[n[0]] = n
# print(union)
# print(dic)
print(N-len(union))
0