結果
問題 | No.1059 素敵な集合 |
ユーザー | hedwig100 |
提出日時 | 2020-05-22 22:18:49 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 1,641 bytes |
コンパイル時間 | 1,508 ms |
コンパイル使用メモリ | 167,268 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-30 15:30:20 |
合計ジャッジ時間 | 2,565 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 14 ms
4,376 KB |
testcase_02 | AC | 3 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 3 ms
4,376 KB |
testcase_07 | AC | 3 ms
4,380 KB |
testcase_08 | AC | 3 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 4 ms
4,376 KB |
testcase_11 | AC | 3 ms
4,380 KB |
testcase_12 | AC | 3 ms
4,376 KB |
testcase_13 | AC | 4 ms
4,380 KB |
testcase_14 | AC | 1 ms
4,376 KB |
testcase_15 | AC | 7 ms
4,380 KB |
testcase_16 | AC | 3 ms
4,376 KB |
testcase_17 | AC | 3 ms
4,380 KB |
testcase_18 | AC | 3 ms
4,380 KB |
testcase_19 | AC | 14 ms
4,376 KB |
testcase_20 | AC | 13 ms
4,376 KB |
testcase_21 | AC | 7 ms
4,380 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i ++) using namespace std; typedef long long ll; typedef pair<ll,ll> PL; typedef pair<int,int> P; const int INF = 1e9; const ll MOD = 1e9 + 7; struct UnionFind { int N; vector<int> parents; UnionFind(int _N) : N(_N){ parents = vector<int>(N,-1); } int find(int x) { //xの親を返す if (parents[x] < 0) return x; return parents[x] = find(parents[x]); } void unite(int x, int y) { //xとyの含むグループを併合 int px = find(x); int py = find(y); if (parents[px] > parents[py]) swap(px,py); if (px != py) { parents[px] += parents[py]; parents[py] = px; } } bool same(int x, int y) { //x,yが同じグループにいるか判定 return find(x) == find(y); } int size(int x) { //xと同じグループのメンバーの個数 return -parents[find(x)]; } vector<int> root() {//ufの根を列挙 vector<int> res; for (int i = 0; i < N; i ++) { if (parents[i] < 0) res.push_back(i); } return res; } int group_count() { //ufのグループの数を数える int cnt = 0; for (int i = 0; i < N; i ++) { if (parents[i] < 0) cnt ++; } return cnt; } }; int main() { int L,R; cin >> L >> R; UnionFind uf(R - L + 1); for (int i = L;i < R + 1;i++){ for (int j = 1;j*i < R + 1;j++){ uf.unite(i - L,j*i - L); } } cout << uf.group_count() - 1 << endl; }