結果

問題 No.1557 Binary Variable
ユーザー momoyuu
提出日時 2024-08-07 20:33:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 101,080 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-08-07 20:33:42
合計ジャッジ時間 6,690 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n,m;
    cin>>n>>m;
    swap(n,m);
    vector<ll> l(n),r(n);
    for(int i = 0;i<n;i++) cin>>l[i]>>r[i];
    ll ans = m;
    vector<int> idx(n);
    for(int i = 0;i<n;i++) idx[i] = i;
    sort(idx.begin(),idx.end(),[&](int i,int j){
        if(r[i]!=r[j]) return r[i] < r[j];
        return l[i] < l[j];
    });
    ll prev = -1;
    for(int i = 0;i<n;i++){
        int ni = idx[i];
        if(prev<l[ni]){
            prev = r[ni];
            ans--;
        }
    }
    cout<<ans<<endl;
}   

0