結果
問題 | No.1059 素敵な集合 |
ユーザー | minato |
提出日時 | 2020-05-22 21:53:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 1,798 bytes |
コンパイル時間 | 2,891 ms |
コンパイル使用メモリ | 239,708 KB |
実行使用メモリ | 8,256 KB |
最終ジャッジ日時 | 2023-09-30 15:28:16 |
合計ジャッジ時間 | 4,194 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 16 ms
4,376 KB |
testcase_02 | AC | 11 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 7 ms
4,380 KB |
testcase_07 | AC | 7 ms
4,376 KB |
testcase_08 | AC | 11 ms
4,376 KB |
testcase_09 | AC | 4 ms
4,376 KB |
testcase_10 | AC | 10 ms
4,376 KB |
testcase_11 | AC | 8 ms
4,380 KB |
testcase_12 | AC | 6 ms
4,376 KB |
testcase_13 | AC | 15 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 24 ms
4,636 KB |
testcase_16 | AC | 9 ms
4,376 KB |
testcase_17 | AC | 10 ms
4,380 KB |
testcase_18 | AC | 28 ms
8,256 KB |
testcase_19 | AC | 19 ms
4,380 KB |
testcase_20 | AC | 21 ms
4,380 KB |
testcase_21 | AC | 26 ms
4,828 KB |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<long long, long long>; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; //constexpr long long MOD = 998244353LL; template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; } template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// struct UnionFind { vector<int> node; UnionFind() = default; UnionFind(int x) {init(x);} void init(int x) { node.assign(x,-1); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (node[x] > node[y]) swap(x,y); node[x] += node[y]; node[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int root(int x) { if (node[x] < 0) return x; return node[x] = root(node[x]); } int size(int x) { return -node[root(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int L,R; cin >> L >> R; UnionFind uf(R-L+1); for (int i = L; i <= R; i++) { for (int j = 2; j*i <= R; j++) { uf.merge(i-L,j*i-L); } } set<int> dic; rep(i,R-L+1) { dic.emplace(uf.root(i)); } cout << dic.size()-1 << ln; }