結果
問題 |
No.1917 LCMST
|
ユーザー |
👑 ![]() |
提出日時 | 2025-05-11 04:39:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 988 bytes |
コンパイル時間 | 4,113 ms |
コンパイル使用メモリ | 292,428 KB |
実行使用メモリ | 29,248 KB |
最終ジャッジ日時 | 2025-05-11 04:39:18 |
合計ジャッジ時間 | 13,512 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 WA * 7 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/dsu> using namespace std; const int MAX = 1e5; void solve() { int N; cin >> N; vector<bool> cnt(MAX + 1); int64_t ans = 0; for (int i = 0; i < N; i++) { int x; cin >> x; if (cnt[x]) ans += x; else cnt[x] = 1; } vector<array<int, 3>> edge; for (int g = 1; g <= MAX; g++) { pair<int, int> prev; for (int i = g, c = 1; i <= MAX; i += g, c++) { if (!cnt[i]) continue; if (prev.first == 0) { prev = {i, c}; continue; } edge.push_back({prev.first, i, prev.second * i}); } } ranges::sort(edge, {}, [](const auto& x) { return x[2]; }); atcoder::dsu uf(MAX + 1); for (auto [x, y, w] : edge) { if (uf.same(x, y)) continue; ans += w; uf.merge(x, y); } cout << ans << '\n'; } int main() { cin.tie(0)->sync_with_stdio(0); solve(); }