結果
| 問題 |
No.1917 LCMST
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-16 15:11:19 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 765 ms / 4,000 ms |
| コード長 | 2,081 bytes |
| コンパイル時間 | 6,249 ms |
| コンパイル使用メモリ | 335,748 KB |
| 実行使用メモリ | 103,320 KB |
| 最終ジャッジ日時 | 2025-07-16 15:11:45 |
| 合計ジャッジ時間 | 24,373 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
// // 多倍長テンプレ
// /* ---------------------- ここから ---------------------- */
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// // 任意長整数型
// using Bint = mp::cpp_int;
// // 仮数部が10進数で1024桁の浮動小数点数型(TLEしたら小さくする)
// using Real = mp::number<mp::cpp_dec_float<1024>>;
// /* ---------------------- ここまで ---------------------- */
using mint = modint998244353;
// using mint = modint1000000007;
ll mod = 998244353;
// ll mod = 1000000007;
ll inf = 2e18;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(a) (a).begin(), (a).end()
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll a[100009];
ll z = 1e5;
vector<ll> Ya[100009];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
ll n;
cin>>n;
rep(i,n){
ll c;
cin>>c;
a[c]++;
}
ll ans = 0;
rep1(i,z){
if(a[i] > 1){
ans += i * (a[i]-1);
a[i] = 1;
}
}
for(int i=1; i<=z; i++){
for(int j=1; i*j<=z; j++){
if(a[i*j] == 0)continue;
Ya[i].emplace_back(i*j);
}
}
vector<vector<ll>> kz;
rep1(i,z){
for(int j=1; j<Ya[i].size(); j++){
kz.emplace_back(vector<ll>{lcm(Ya[i][0],Ya[i][j]),Ya[i][0],Ya[i][j]});
}
}
sort(all(kz));
dsu d(z+1);
for(auto v : kz){
if(!d.same(v[1],v[2])){
d.merge(v[1],v[2]);
ans += v[0];
}
}
cout << ans << endl;
}