結果
| 問題 |
No.1917 LCMST
|
| コンテスト | |
| ユーザー |
MZKi
|
| 提出日時 | 2025-07-15 19:21:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,929 bytes |
| コンパイル時間 | 4,588 ms |
| コンパイル使用メモリ | 265,004 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-15 19:21:38 |
| 合計ジャッジ時間 | 12,358 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 41 |
ソースコード
#include<atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
using P = pair<pair<ll, ll>, pair<int, int>>;
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n)cin >> a[i];
vector<vector<pair<ll, int>>> vec(100010);
rep(i, n) {
for(ll x = 1; x * x <= a[i]; x++) {
if(a[i] % x == 0) {
vec[x].push_back({a[i]/x, i});
if(x * x != a[i])vec[a[i]/x].push_back({x, i});
}
}
}
priority_queue<P, vector<P>, greater<P>> que;
REP(i, 100000) {
sort(all(vec[i]));
if(vec[i].size() <= 1)continue;
que.push({{vec[i][0].first * vec[i][1].first * i, i}, {0, 1}});
}
dsu uf(n);
ll ans = 0;
while(uf.size(0) != n) {
P p = que.top();
que.pop();
ll x = p.first.second;
int idx1 = p.second.first;
int idx2 = p.second.second;
if(idx1 + 1 != idx2 && idx1 + 1 < vec[x].size())que.push({{vec[x][idx1 + 1].first * vec[x][idx2].first * x, x}, {idx1 + 1, idx2}});
if(idx1 != idx2 + 1 && idx2 + 1 < vec[x].size())que.push({{vec[x][idx1].first * vec[x][idx2 + 1].first * x, x}, {idx1, idx2 + 1}});
if(!uf.same(vec[x][idx1].second, vec[x][idx2].second)) {
uf.merge(vec[x][idx1].second, vec[x][idx2].second);
ans += p.first.first;
}
}
cout << ans << endl;
}
MZKi