結果
問題 |
No.1917 LCMST
|
ユーザー |
👑 ![]() |
提出日時 | 2025-05-11 04:41:36 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 206 ms / 4,000 ms |
コード長 | 996 bytes |
コンパイル時間 | 5,032 ms |
コンパイル使用メモリ | 292,872 KB |
実行使用メモリ | 54,144 KB |
最終ジャッジ日時 | 2025-05-11 04:41:51 |
合計ジャッジ時間 | 13,984 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/dsu> using namespace std; using ll = long long; const ll MAX = 1e5; void solve() { ll N; cin >> N; vector<bool> cnt(MAX + 1); ll ans = 0; for (ll i = 0; i < N; i++) { ll x; cin >> x; if (cnt[x]) ans += x; else cnt[x] = 1; } vector<array<ll, 3>> edge; for (ll g = 1; g <= MAX; g++) { pair<ll, ll> prev; for (ll 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(); }