結果

問題 No.1059 素敵な集合
ユーザー definedefine
提出日時 2020-05-22 22:52:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 202,028 KB
実行使用メモリ 6,480 KB
最終ジャッジ日時 2023-09-30 15:32:10
合計ジャッジ時間 3,047 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 16 ms
6,480 KB
testcase_02 AC 6 ms
4,676 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 6 ms
4,504 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 8 ms
4,676 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 8 ms
4,860 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 13 ms
6,240 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 5 ms
4,500 KB
testcase_18 AC 4 ms
4,888 KB
testcase_19 AC 24 ms
6,252 KB
testcase_20 AC 24 ms
6,412 KB
testcase_21 AC 14 ms
6,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

struct UnionFind{
	vector<int>par,size;
	int find(int x){
		return (par[x]==x?x:par[x]=find(par[x]));
	}
	void merge(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		if(size[x]<size[y]){
			par[x]=y;
			size[y]+=size[x];
		}else {
			par[y]=x;
			size[y]+=size[x];
		}
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	UnionFind(int x){
		rep(i,x){
			par.pb(i);size.pb(1);
		}
	}
};
int L,R;
signed main(){
	cin>>L>>R;
	int ans=0;
	UnionFind uf(R-L+1);
	for(int i=L;i<=R;i++){
		for(int j=2;i*j<=R;j++){
			uf.merge(i-L,i*j-L);
		}
	}
	rep(i,R-L+1){
		ans+=uf.find(i)==i;
	}
	cout<<ans-1<<endl;
}
0