結果

問題 No.1557 Binary Variable
ユーザー rtyurtyu
提出日時 2021-07-12 14:41:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 78,964 KB
実行使用メモリ 11,148 KB
最終ジャッジ日時 2023-09-14 20:33:54
合計ジャッジ時間 7,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
10,760 KB
testcase_01 AC 66 ms
9,516 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 60 ms
9,496 KB
testcase_05 AC 60 ms
10,600 KB
testcase_06 AC 58 ms
10,392 KB
testcase_07 AC 60 ms
11,044 KB
testcase_08 AC 66 ms
10,276 KB
testcase_09 AC 70 ms
9,472 KB
testcase_10 AC 77 ms
9,192 KB
testcase_11 AC 76 ms
10,864 KB
testcase_12 AC 66 ms
10,256 KB
testcase_13 AC 76 ms
10,112 KB
testcase_14 AC 80 ms
9,740 KB
testcase_15 AC 77 ms
10,576 KB
testcase_16 AC 80 ms
9,828 KB
testcase_17 AC 77 ms
10,640 KB
testcase_18 AC 81 ms
9,744 KB
testcase_19 AC 81 ms
9,544 KB
testcase_20 AC 81 ms
10,340 KB
testcase_21 AC 81 ms
9,740 KB
testcase_22 AC 81 ms
10,056 KB
testcase_23 AC 81 ms
10,040 KB
testcase_24 AC 83 ms
9,864 KB
testcase_25 AC 83 ms
10,672 KB
testcase_26 AC 84 ms
11,148 KB
testcase_27 AC 86 ms
9,544 KB
testcase_28 AC 84 ms
11,052 KB
testcase_29 AC 87 ms
9,748 KB
testcase_30 AC 85 ms
9,572 KB
testcase_31 AC 86 ms
10,744 KB
testcase_32 AC 86 ms
9,752 KB
testcase_33 AC 82 ms
9,600 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct pnt
{
    int p, i;
    bool f;
    bool operator<(const pnt& r) {
        if (p != r.p) return p < r.p;
        return f < r.f;
    }
    pnt(int p, bool f, int i) : p(p), f(f), i(i) {};
    pnt() : p(0), f(false), i(0) {};
};

bool rp[200009];
vector<pnt> v;
vector<int> pv;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int l, r; cin >> l >> r;
        v.push_back(pnt(l, 0, i));
        v.push_back(pnt(r, 1, i));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
        if (rp[v[i].i]) continue;
        if (v[i].f) {
            while (!pv.empty()) {
                rp[pv.back()] = true;
                pv.pop_back();
            }
            n--;
        }
        else
            pv.push_back(v[i].i);
    }
    cout << n << '\n';
    return 0;
}
0