結果
| 問題 | 
                            No.1917 LCMST
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-02-11 02:37:50 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 969 bytes | 
| コンパイル時間 | 1,941 ms | 
| コンパイル使用メモリ | 202,752 KB | 
| 最終ジャッジ日時 | 2025-02-10 14:00:53 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 9 WA * 33 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())
const int maxn=100005;
int par[maxn];
int Find(int x){return x==par[x]?x:par[x]=Find(par[x]);}
signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int n; cin >> n;
    vector<int> a(n),cnt(maxn);
    vector<array<ll,3>> e;
    for(int i=0; i<maxn; ++i) par[i]=i;
    for(auto& i: a) cin >> i,cnt[i]++;
    ll res=0;
    for(int i=1; i<maxn; ++i) if(cnt[i]){
        res+=1ll*(cnt[i]-1)*i,cnt[i]=1;
        for(int j=i*2; j<maxn; j+=i) res+=1ll*cnt[j]*j,cnt[j]=0;
    }
    for(int i=1; i<maxn; ++i){
        vector<int> vec;
        for(int j=i; j<maxn; j+=i) if(cnt[j]) vec.pb(j);
        for(int j=1; j<vec.size(); ++j) e.pb({1ll*vec[0]*vec[j]/i,vec[0],vec[j]});
    }
    sort(all(e));
    for(auto& [w,u,v]: e) if(Find(u)!=Find(v)) par[u]=v,res+=w;
    cout << res << "\n";
}