結果

問題 No.1557 Binary Variable
ユーザー もなもな
提出日時 2021-06-25 23:03:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,438 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 202,320 KB
実行使用メモリ 5,232 KB
最終ジャッジ日時 2023-09-07 14:55:34
合計ジャッジ時間 5,568 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
5,096 KB
testcase_01 AC 43 ms
5,140 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 32 ms
5,088 KB
testcase_05 AC 32 ms
5,080 KB
testcase_06 AC 31 ms
5,148 KB
testcase_07 AC 31 ms
5,088 KB
testcase_08 AC 33 ms
5,232 KB
testcase_09 AC 33 ms
5,204 KB
testcase_10 AC 36 ms
5,196 KB
testcase_11 AC 36 ms
5,196 KB
testcase_12 AC 33 ms
5,144 KB
testcase_13 AC 36 ms
5,140 KB
testcase_14 AC 38 ms
5,096 KB
testcase_15 AC 36 ms
5,192 KB
testcase_16 AC 39 ms
5,228 KB
testcase_17 AC 38 ms
5,148 KB
testcase_18 AC 38 ms
5,160 KB
testcase_19 AC 42 ms
5,080 KB
testcase_20 AC 41 ms
5,168 KB
testcase_21 AC 41 ms
5,140 KB
testcase_22 AC 42 ms
5,196 KB
testcase_23 AC 42 ms
5,196 KB
testcase_24 AC 43 ms
5,076 KB
testcase_25 AC 43 ms
5,080 KB
testcase_26 AC 44 ms
5,228 KB
testcase_27 AC 43 ms
5,196 KB
testcase_28 AC 44 ms
5,220 KB
testcase_29 AC 47 ms
5,080 KB
testcase_30 AC 45 ms
5,164 KB
testcase_31 AC 46 ms
5,160 KB
testcase_32 AC 46 ms
5,088 KB
testcase_33 AC 41 ms
5,084 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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));
    }

    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()){
        auto p = intersection(nint,*itr);
        if(p == nullp){
            nint = *itr;
            ct++;
        } else {
            nint = p;
        }
        itr++;
    }
    ct++;
    ans = N-ct;
    if(flg) prl(ans); else prl(-1);
//    if(flg) prl("Yes"); else prl("No");
}
0