結果
問題 | No.1059 素敵な集合 |
ユーザー | scol_kp |
提出日時 | 2020-05-22 22:40:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 1,872 bytes |
コンパイル時間 | 2,200 ms |
コンパイル使用メモリ | 211,676 KB |
実行使用メモリ | 9,532 KB |
最終ジャッジ日時 | 2024-07-23 09:32:09 |
合計ジャッジ時間 | 3,078 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 18 ms
6,940 KB |
testcase_02 | AC | 8 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 6 ms
6,944 KB |
testcase_07 | AC | 6 ms
6,944 KB |
testcase_08 | AC | 8 ms
6,944 KB |
testcase_09 | AC | 4 ms
6,940 KB |
testcase_10 | AC | 9 ms
6,940 KB |
testcase_11 | AC | 7 ms
6,940 KB |
testcase_12 | AC | 5 ms
6,944 KB |
testcase_13 | AC | 11 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 18 ms
6,940 KB |
testcase_16 | AC | 8 ms
6,944 KB |
testcase_17 | AC | 8 ms
6,940 KB |
testcase_18 | AC | 15 ms
9,532 KB |
testcase_19 | AC | 20 ms
6,940 KB |
testcase_20 | AC | 20 ms
6,940 KB |
testcase_21 | AC | 19 ms
7,168 KB |
ソースコード
#include <bits/stdc++.h> #define FASTIO using namespace std; using ll = long long; using Vi = vector<int>; using Vl = vector<ll>; using Pii = pair<int, int>; using Pll = pair<ll, ll>; constexpr int I_INF = numeric_limits<int>::max(); constexpr ll L_INF = numeric_limits<ll>::max(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% class UnionFind { using i64 = std::int64_t; private: std::vector<i64> par; std::vector<i64> sz; public: UnionFind(i64 N) : par(N), sz(N, 1) { for (i64 i = 0; i < N; ++i) par[i] = i; } i64 root(i64 x) { return par[x] == x ? x : par[x] = root(par[x]); } bool same(i64 x, i64 y) { return root(x) == root(y); } void unite(i64 x, i64 y) { x = root(x); y = root(y); if (x == y) return; if (sz[x] < sz[y]) std::swap(x, y); par[y] = x; sz[x] += sz[y]; } i64 size(i64 x) { return sz[root(x)]; } void reset(i64 N) { par.resize(N); for (i64 i = 0; i < N; ++i) par[i] = i; sz.assign(N, 1); } }; void solve() { ll L, R; cin >> L >> R; UnionFind uf(R - L + 1); for (ll i = L; i <= R; i++) { for (ll j = 2 * i; j <= R; j += i) { uf.unite(i - L, j - L); } } unordered_set<ll> st; for (ll i = 0; i < R - L + 1; i++) { st.emplace(uf.root(i)); } cout << (ll)st.size() - 1 << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); #endif #ifdef FILEINPUT ifstream ifs("./in_out/input.txt"); cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT ofstream ofs("./in_out/output.txt"); cout.rdbuf(ofs.rdbuf()); #endif solve(); cout << flush; return 0; }