結果

問題 No.1917 LCMST
ユーザー i_am_noobi_am_noob
提出日時 2023-02-11 02:39:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 4,000 ms
コード長 981 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 209,916 KB
実行使用メモリ 21,288 KB
最終ジャッジ日時 2023-09-22 02:43:06
合計ジャッジ時間 9,142 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 5 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 97 ms
9,340 KB
testcase_10 AC 96 ms
9,228 KB
testcase_11 AC 100 ms
11,600 KB
testcase_12 AC 137 ms
20,648 KB
testcase_13 AC 143 ms
20,656 KB
testcase_14 AC 122 ms
14,544 KB
testcase_15 AC 115 ms
15,848 KB
testcase_16 AC 143 ms
20,436 KB
testcase_17 AC 170 ms
21,288 KB
testcase_18 AC 163 ms
20,536 KB
testcase_19 AC 107 ms
12,204 KB
testcase_20 AC 101 ms
10,920 KB
testcase_21 AC 108 ms
11,000 KB
testcase_22 AC 101 ms
10,928 KB
testcase_23 AC 100 ms
10,928 KB
testcase_24 AC 108 ms
10,940 KB
testcase_25 AC 101 ms
12,020 KB
testcase_26 AC 103 ms
11,052 KB
testcase_27 AC 104 ms
11,040 KB
testcase_28 AC 106 ms
11,160 KB
testcase_29 AC 86 ms
7,672 KB
testcase_30 AC 86 ms
7,708 KB
testcase_31 AC 85 ms
7,680 KB
testcase_32 AC 85 ms
7,672 KB
testcase_33 AC 86 ms
7,672 KB
testcase_34 AC 85 ms
7,856 KB
testcase_35 AC 86 ms
7,856 KB
testcase_36 AC 84 ms
7,672 KB
testcase_37 AC 88 ms
8,476 KB
testcase_38 AC 88 ms
8,452 KB
testcase_39 AC 88 ms
8,404 KB
testcase_40 AC 88 ms
8,408 KB
testcase_41 AC 88 ms
8,420 KB
testcase_42 AC 89 ms
8,416 KB
testcase_43 AC 86 ms
8,060 KB
testcase_44 AC 86 ms
8,036 KB
権限があれば一括ダウンロードができます

ソースコード

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[Find(u)]=Find(v),res+=w;
    cout << res << "\n";
}
0