結果
問題 | No.1059 素敵な集合 |
ユーザー | kimiyuki |
提出日時 | 2020-05-22 22:06:47 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,240 bytes |
コンパイル時間 | 2,337 ms |
コンパイル使用メモリ | 215,052 KB |
実行使用メモリ | 295,288 KB |
最終ジャッジ日時 | 2024-10-05 17:40:26 |
合計ジャッジ時間 | 8,254 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1,384 ms
295,288 KB |
testcase_02 | AC | 57 ms
20,676 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 53 ms
18,592 KB |
testcase_07 | AC | 49 ms
18,172 KB |
testcase_08 | AC | 77 ms
26,064 KB |
testcase_09 | AC | 11 ms
6,816 KB |
testcase_10 | AC | 178 ms
50,576 KB |
testcase_11 | AC | 61 ms
21,080 KB |
testcase_12 | AC | 24 ms
10,256 KB |
testcase_13 | AC | 143 ms
43,716 KB |
testcase_14 | WA | - |
testcase_15 | AC | 347 ms
90,864 KB |
testcase_16 | AC | 65 ms
21,616 KB |
testcase_17 | AC | 55 ms
18,688 KB |
testcase_18 | WA | - |
testcase_19 | AC | 1,252 ms
288,840 KB |
testcase_20 | AC | 1,164 ms
282,192 KB |
testcase_21 | AC | 286 ms
77,632 KB |
ソースコード
#line 1 "main.cpp" #include <bits/stdc++.h> #line 2 "/home/user/GitHub/competitive-programming-library/utils/macros.hpp" #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) #define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) #define ALL(x) std::begin(x), std::end(x) #line 3 "/home/user/GitHub/competitive-programming-library/data_structure/union_find_tree.hpp" /** * @brief Union-Find Tree * @docs data_structure/union_find_tree.md * @note union-by-size + path-compression */ struct union_find_tree { std::vector<int> data; union_find_tree() = default; explicit union_find_tree(std::size_t n) : data(n, -1) {} bool is_root(int i) { return data[i] < 0; } int find_root(int i) { return is_root(i) ? i : (data[i] = find_root(data[i])); } int tree_size(int i) { return - data[find_root(i)]; } int unite_trees(int i, int j) { i = find_root(i); j = find_root(j); if (i != j) { if (tree_size(i) < tree_size(j)) std::swap(i, j); data[i] += data[j]; data[j] = i; } return i; } bool is_same(int i, int j) { return find_root(i) == find_root(j); } }; #line 8 "/home/user/GitHub/competitive-programming-library/graph/kruskal.hpp" /** * @brief minimum spanning tree / 最小全域木 (Kruskal's method) * @note $O(E \log E)$ * @note it becomes a forest if the given graph is not connected * @return a list of indices of edges */ template <typename T> std::vector<int> compute_minimum_spanning_tree(int n, std::vector<std::tuple<int, int, T> > edges) { std::vector<int> order(edges.size()); std::iota(ALL(order), 0); std::sort(ALL(order), [&](int i, int j) { return std::make_pair(std::get<2>(edges[i]), i) < std::make_pair(std::get<2>(edges[j]), j); }); std::vector<int> tree; union_find_tree uft(n); for (int i : order) { int x = std::get<0>(edges[i]); int y = std::get<1>(edges[i]); if (not uft.is_same(x, y)) { uft.unite_trees(x, y); tree.push_back(i); } } return tree; } #line 4 "main.cpp" using namespace std; int64_t solve(int l, int r) { // [l, r) vector<tuple<int, int, int64_t> > edges; auto use = [&](int i, int j) { edges.emplace_back(i - l, j - l, min(i % j, j % i)); }; REP3 (i, l, r) { REP3 (j, i + 1, min(100, 2 * i)) if (j < r) { use(i, j); } for (int j = 2 * i; j < r; j += i) { REP (k, min(4, i)) if (j + k < r) { use(i, j + k); } } } int64_t ans = 0; vector<int> used = compute_minimum_spanning_tree(r - l, edges); for (int i : used) { ans += get<2>(edges[i]); } return ans; } // generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator) int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); constexpr char endl = '\n'; int64_t L, R; cin >> L >> R; ++ R; auto ans = solve(L, R); cout << ans << endl; return 0; }