結果

問題 No.1917 LCMST
ユーザー 👑 NachiaNachia
提出日時 2022-04-29 22:42:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 253 ms / 4,000 ms
コード長 1,413 bytes
コンパイル時間 1,316 ms
コンパイル使用メモリ 114,072 KB
実行使用メモリ 39,020 KB
最終ジャッジ日時 2023-09-11 14:05:46
合計ジャッジ時間 11,213 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,560 KB
testcase_01 AC 6 ms
4,588 KB
testcase_02 AC 6 ms
4,628 KB
testcase_03 AC 8 ms
4,956 KB
testcase_04 AC 8 ms
5,016 KB
testcase_05 AC 8 ms
4,948 KB
testcase_06 AC 8 ms
4,980 KB
testcase_07 AC 8 ms
5,172 KB
testcase_08 AC 6 ms
4,624 KB
testcase_09 AC 235 ms
37,740 KB
testcase_10 AC 235 ms
37,504 KB
testcase_11 AC 229 ms
37,820 KB
testcase_12 AC 200 ms
22,384 KB
testcase_13 AC 129 ms
13,028 KB
testcase_14 AC 219 ms
37,796 KB
testcase_15 AC 109 ms
10,320 KB
testcase_16 AC 129 ms
14,180 KB
testcase_17 AC 150 ms
21,164 KB
testcase_18 AC 167 ms
21,752 KB
testcase_19 AC 117 ms
9,532 KB
testcase_20 AC 105 ms
6,784 KB
testcase_21 AC 120 ms
10,384 KB
testcase_22 AC 104 ms
6,752 KB
testcase_23 AC 104 ms
6,804 KB
testcase_24 AC 118 ms
9,264 KB
testcase_25 AC 105 ms
6,756 KB
testcase_26 AC 110 ms
10,056 KB
testcase_27 AC 113 ms
8,932 KB
testcase_28 AC 115 ms
9,212 KB
testcase_29 AC 237 ms
38,060 KB
testcase_30 AC 238 ms
38,268 KB
testcase_31 AC 238 ms
37,612 KB
testcase_32 AC 237 ms
37,688 KB
testcase_33 AC 244 ms
39,020 KB
testcase_34 AC 85 ms
4,624 KB
testcase_35 AC 85 ms
4,592 KB
testcase_36 AC 86 ms
4,564 KB
testcase_37 AC 253 ms
38,952 KB
testcase_38 AC 248 ms
38,480 KB
testcase_39 AC 251 ms
38,768 KB
testcase_40 AC 248 ms
38,136 KB
testcase_41 AC 250 ms
37,864 KB
testcase_42 AC 246 ms
37,504 KB
testcase_43 AC 87 ms
5,076 KB
testcase_44 AC 87 ms
5,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <atcoder/modint>
#include <atcoder/dsu>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using m32 = atcoder::static_modint<1000000007>;

const int Z = 100000;

int main(){
    int N; cin >> N;
    vector<int> A(Z+1);
    u64 ans = 0;
    rep(i,N){
        int a; cin >> a;
        if(A[a]) ans += a;
        A[a] = 1;
    }

    atcoder::dsu dsu(Z+1);

    vector<pair<int, int>> V(Z+1, make_pair(Z+1, -1));

    for(int z=Z; z>=1; z--) for(int p=z; p<=Z; p+=z) if(A[p]) V[z] = min(V[z], make_pair(p / z, p));
    for(int z=Z; z>=1; z--) for(int p=z; p<=Z; p+=z) if(A[p]) V[p] = min(V[p], V[z]);

    vector<pair<i64, pair<int, int>>> edges;
    for(int z=Z; z>=1; z--) for(int p=z; p<=Z; p+=z) if(A[p]) if(V[z].first != Z+1){
        edges.push_back(make_pair((i64)V[z].first * p, make_pair(V[z].second, p)));
    }

    sort(edges.begin(), edges.end());
    for(auto [d,e] : edges){
        if(dsu.same(e.first, e.second)) continue;
        dsu.merge(e.first, e.second);
        ans += d;
    }
    cout << ans << '\n';
    return 0;
}

struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0