結果
問題 | No.1917 LCMST |
ユーザー |
|
提出日時 | 2024-03-12 23:40:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,916 bytes |
コンパイル時間 | 1,557 ms |
コンパイル使用メモリ | 174,092 KB |
実行使用メモリ | 42,708 KB |
最終ジャッジ日時 | 2024-09-29 22:29:24 |
合計ジャッジ時間 | 9,685 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 WA * 33 |
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:77:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 77 | for (auto [w, u, v] : total) | ^
ソースコード
//Make CSP great again//Vengeance#include <bits/stdc++.h>#define TASK "TESTCODE"using namespace std;const int N = 1e6, M = 1e5;int lab[N + 1];int last[M + 1];int FindSet(int u){return lab[u] < 0 ? u : lab[u] = FindSet(lab[u]);}bool unite(int u, int v){u = FindSet(u);v = FindSet(v);if (u == v){return false;}if (lab[u] > lab[v]){swap(u, v);}lab[u] += lab[v];lab[v] = u;return true;}int rep[M + 1];int n;long long res = 0;void read(){cin >> n;for (int i = 1; i <= n; ++ i){int a;cin >> a;lab[i] = -1;if (rep[a]){res += a;unite(rep[a], i);}rep[a] = i;}}void solve(){vector<tuple<long long, int, int> > total;for (int i = 1; i <= M; ++ i){for (int j = i; j <= M; j += i){if (rep[j]){last[i] = j;break;}}}for (int i = 1; i <= M; ++ i){if (!last[i]){continue;}for (int j = i; j <= M; j += i){if (rep[j]){total.emplace_back(1LL * last[i] * j/__gcd(last[i], j), last[i], j);}}}for (auto [w, u, v] : total){res += 1LL * w * unite(rep[u], rep[v]);}assert(lab[FindSet(1)] == -n);cout << res;}int main(){ios_base::sync_with_stdio(false);cin.tie(nullptr);if (fopen(TASK".INP", "r")){freopen(TASK".INP", "r", stdin);//freopen(TASK".OUT", "w", stdout);}int t = 1;bool typetest = false;if (typetest){cin >> t;}for (int __ = 1; __ <= t; ++ __){//cout << "Case " << __ << ": ";read();solve();}}