結果

問題 No.1059 素敵な集合
ユーザー hs0319boyhs0319boy
提出日時 2020-05-23 00:10:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,522 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 171,528 KB
実行使用メモリ 9,372 KB
最終ジャッジ日時 2023-09-30 15:35:28
合計ジャッジ時間 2,898 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,572 KB
testcase_01 AC 3 ms
4,492 KB
testcase_02 AC 13 ms
5,368 KB
testcase_03 AC 3 ms
4,632 KB
testcase_04 AC 3 ms
4,636 KB
testcase_05 AC 3 ms
4,408 KB
testcase_06 AC 8 ms
5,140 KB
testcase_07 AC 8 ms
4,900 KB
testcase_08 AC 11 ms
5,104 KB
testcase_09 AC 5 ms
5,000 KB
testcase_10 AC 9 ms
4,884 KB
testcase_11 AC 9 ms
4,904 KB
testcase_12 AC 7 ms
4,956 KB
testcase_13 AC 15 ms
5,364 KB
testcase_14 AC 4 ms
4,896 KB
testcase_15 AC 22 ms
5,372 KB
testcase_16 AC 10 ms
5,404 KB
testcase_17 AC 11 ms
5,504 KB
testcase_18 AC 29 ms
9,372 KB
testcase_19 AC 15 ms
4,832 KB
testcase_20 AC 17 ms
5,224 KB
testcase_21 AC 25 ms
5,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

vin par(200050);
vin deep(200050);
void init(int n);
int root(int x);
void unite(int x,int y);
bool same(int x,int y);

int main(){
    int l,r;cin>>l>>r;
    if(l==1){
        cout<<0<<endl;
        return 0;
    }
    init(r-l+1);
    rep2(i,l,r+1)for(int j=2*i;j<r+1;j+=i){
        if(!same(i-l,j-l))unite(i-l,j-l);
    }
    set<int> tmp;
    int ans=0;
    rep(i,r-l+1)tmp.insert(root(i));
    cout<<tmp.size()-1<<endl;
}

void init(int n){
    rep(i,n){
        par[i]=i;
        deep[i]=0;
    }
}
int root(int x){
    if(par[x]==x)return x;
    else return par[x]=root(par[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return;
    if(deep[x]<deep[y])par[x]=y;
    else{
        par[y]=x;
        if(deep[x]==deep[y])deep[x]++;
    }
}
bool same(int x,int y){
    return root(x)==root(y);
}
0