結果
| 問題 | No.1059 素敵な集合 |
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2020-05-22 21:34:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,006 bytes |
| コンパイル時間 | 1,582 ms |
| コンパイル使用メモリ | 173,720 KB |
| 実行使用メモリ | 8,832 KB |
| 最終ジャッジ日時 | 2024-07-23 09:25:10 |
| 合計ジャッジ時間 | 2,477 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;
s32 ri() {
s32 n;
scanf("%" SCNd32, &n);
return n;
}
struct UnionFind {
std::vector<int> data;
UnionFind (int size) : data(size, -1) {}
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x]) std::swap(x, y);
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool same(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)]; }
bool connected() { return size(0) == (int) data.size(); }
};
int main() {
#define int WHOOOO // 脱int訓練中につき許して
s32 l = ri(), r = ri();
UnionFind uni(r + 1);
for (s32 i = l; i <= r; i++)
for (s32 j = i * 2; j <= r; j += i) uni.unite(i, j);
std::set<s32> all;
for (s32 i = l; i <= r; i++) all.insert(uni.root(i));
printf("%" PRId32 "\n", (s32) all.size() - 1);
return 0;
}
QCFium