結果
| 問題 | No.1917 LCMST |
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2026-08-03 17:05:24 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 237 ms / 4,000 ms |
| + 795µs | |
| コード長 | 2,177 bytes |
| 記録 | |
| コンパイル時間 | 4,141 ms |
| コンパイル使用メモリ | 386,292 KB |
| 実行使用メモリ | 90,992 KB |
| 最終ジャッジ日時 | 2026-08-03 17:06:04 |
| 合計ジャッジ時間 | 15,066 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
/**
author: shobonvip
created: 2026.08.03 16:57:13
**/
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vector<ll> a(n);
rep(i,0,n) cin >> a[i];
const int mx = 105000;
vector<ll> have(mx);
rep(i,0,n) {
have[a[i]]++;
}
ll ans = 0;
rep(i,0,mx) {
if (have[i] >= 2) {
ans += (have[i]-1) * i;
}
}
vector bucket(mx, queue<ll>());
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
vector<ll> val(mx);
rep(i,1,mx) {
for (int j=i; j<mx; j+=i) {
if (have[j] >= 1) {
bucket[i].push(j);
}
}
if (bucket[i].empty()) continue;
ll v = bucket[i].front();
val[i] = v;
bucket[i].pop();
if (bucket[i].empty()) continue;
ll w = bucket[i].front();
pq.push(pair(v * w / i, i));
}
dsu uf(mx);
while (!pq.empty()) {
auto [tmp, i] = pq.top();
pq.pop();
if (!uf.same(bucket[i].front(), val[i])) {
ans += tmp;
uf.merge(bucket[i].front(), val[i]);
}
bucket[i].pop();
if (bucket[i].empty()) continue;
ll w = bucket[i].front();
pq.push(pair(val[i] * w / i, i));
}
cout << ans << endl;
}
shobonvip