結果

問題 No.1557 Binary Variable
ユーザー もなもな
提出日時 2021-06-25 23:08:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,449 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 207,060 KB
実行使用メモリ 5,392 KB
最終ジャッジ日時 2023-09-07 14:57:34
合計ジャッジ時間 5,817 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
5,072 KB
testcase_01 AC 48 ms
5,080 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 38 ms
5,196 KB
testcase_05 AC 38 ms
5,060 KB
testcase_06 AC 37 ms
5,096 KB
testcase_07 AC 38 ms
5,128 KB
testcase_08 AC 40 ms
5,196 KB
testcase_09 AC 40 ms
5,284 KB
testcase_10 AC 43 ms
5,220 KB
testcase_11 AC 43 ms
5,068 KB
testcase_12 AC 40 ms
5,072 KB
testcase_13 AC 42 ms
5,124 KB
testcase_14 AC 45 ms
5,132 KB
testcase_15 AC 43 ms
5,068 KB
testcase_16 AC 45 ms
5,140 KB
testcase_17 AC 45 ms
5,072 KB
testcase_18 AC 44 ms
5,188 KB
testcase_19 AC 46 ms
5,192 KB
testcase_20 AC 46 ms
5,160 KB
testcase_21 AC 46 ms
5,204 KB
testcase_22 AC 47 ms
5,064 KB
testcase_23 AC 46 ms
5,164 KB
testcase_24 AC 48 ms
5,196 KB
testcase_25 AC 48 ms
5,124 KB
testcase_26 AC 49 ms
5,192 KB
testcase_27 AC 48 ms
5,208 KB
testcase_28 AC 50 ms
5,200 KB
testcase_29 AC 51 ms
5,208 KB
testcase_30 AC 51 ms
5,188 KB
testcase_31 AC 52 ms
5,192 KB
testcase_32 AC 52 ms
5,132 KB
testcase_33 AC 46 ms
5,392 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++)
#define pr(a) cout << a
#define prl(a) cout << (a) << endl
#define prld(a) cout << setprecision(15)<< (a) << endl 
#define allrange(a) a.begin(),a.end()

pair<int,int> intersection(pair<int,int> &pa,pair<int,int> &pb){

    int l = max(pa.first,pb.first);
    int r = min(pa.second,pb.second);
    if(r<=l) return make_pair(0,0); 
    return make_pair(l,r);
}

int main(){
    std::cin.tie(0); // cinとcoutの同期を解除
    std::ios::sync_with_stdio(false);
//    int N;cin >> N;
    int N,M;cin >> N>>M;
//  int N,M,K;cin >> N>>M>>K;
    bool flg=true;
    int ans=0;

    vector<pair<int,int>> ints;
     
    rep(i,M){
        int l, r;
        cin >> l >> r;
        ints.push_back(make_pair(l,r+1));
    }

    sort(allrange(ints));
    
    const pair<int,int> nullp=make_pair(0,0);
    auto itr = ints.begin();
    pair<int,int> nint = *itr;
    itr++;
    int ct = 0;
    while(itr!= ints.end()){
        nint = intersection(nint,*itr);
        if(nint == nullp){
            nint = *itr;
            ct++;
        }
        itr++;
    }
    if(nint != nullp) ct++;
    ans = N-ct;
    if(flg) prl(ans); else prl(-1);
//    if(flg) prl("Yes"); else prl("No");
}
0