結果

問題 No.1917 LCMST
ユーザー i_am_noobi_am_noob
提出日時 2023-02-11 02:37:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 969 bytes
コンパイル時間 2,498 ms
コンパイル使用メモリ 208,400 KB
実行使用メモリ 21,300 KB
最終ジャッジ日時 2023-09-22 02:41:31
合計ジャッジ時間 9,760 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 89 ms
7,676 KB
testcase_30 AC 86 ms
7,664 KB
testcase_31 AC 87 ms
7,772 KB
testcase_32 AC 86 ms
7,676 KB
testcase_33 AC 88 ms
7,684 KB
testcase_34 AC 85 ms
7,616 KB
testcase_35 AC 85 ms
7,700 KB
testcase_36 AC 85 ms
7,828 KB
testcase_37 AC 89 ms
8,384 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
}
0