結果
| 問題 |
No.1059 素敵な集合
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-05-22 21:48:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 1,056 bytes |
| コンパイル時間 | 876 ms |
| コンパイル使用メモリ | 91,020 KB |
| 実行使用メモリ | 8,704 KB |
| 最終ジャッジ日時 | 2024-07-23 09:27:53 |
| 合計ジャッジ時間 | 1,686 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
bool ok[200005];
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) { }
bool unionSet(int x, int y) {
x = root(x); y = root(y);
if (x != y) {
if (data[y] < data[x]) swap(x, y);
data[x] += data[y]; data[y] = x;
}
return x != y;
}
bool findSet(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
return data[x] < 0 ? x : data[x] = root(data[x]);
}
int size(int x) {
return -data[root(x)];
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int L, R;
cin >> L >> R;
UnionFind uf(R+1);
for(int i = L; i <= R; i++){
for(int j = 2; i*j <= R; j++){
uf.unionSet(i, i*j);
}
}
set<int> st;
for(int i = L; i <= R; i++){
st.insert(uf.root(i));
}
cout << st.size()-1 << endl;
}
milanis48663220