結果
問題 | No.1059 素敵な集合 |
ユーザー |
|
提出日時 | 2024-03-31 06:58:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 346 ms / 2,000 ms |
コード長 | 672 bytes |
コンパイル時間 | 1,878 ms |
コンパイル使用メモリ | 208,308 KB |
最終ジャッジ日時 | 2025-02-20 16:07:04 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> #include <atcoder/dsu> using namespace std; using namespace atcoder; using ll = long long; using mint = modint; using edge = pair<ll, pair<int, int>>; int main() { vector<edge> ED; int L, R;cin >> L >> R; int N = R - L + 1; for (int l = L;l < R;l++) { ED.push_back({1, {l - L, l + 1 - L}}); int now = 2 * l; while (now <= R) { ED.push_back({0LL, {l - L, now - L}}); now += l; } } sort(ED.begin(), ED.end()); dsu uf(N); ll ans = 0; for (auto ed : ED) { int a = ed.second.first;int b = ed.second.second; if (!uf.same(a, b)) { uf.merge(a, b); ans += ed.first; } } cout << ans << endl; }