結果

問題 No.1917 LCMST
ユーザー ruthenruthen
提出日時 2022-04-29 23:22:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,463 bytes
コンパイル時間 2,728 ms
コンパイル使用メモリ 216,520 KB
実行使用メモリ 814,452 KB
最終ジャッジ日時 2023-09-11 14:57:07
合計ジャッジ時間 10,122 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
14,328 KB
testcase_01 AC 54 ms
14,624 KB
testcase_02 AC 58 ms
14,048 KB
testcase_03 AC 147 ms
23,144 KB
testcase_04 AC 152 ms
23,944 KB
testcase_05 AC 145 ms
22,428 KB
testcase_06 AC 150 ms
22,796 KB
testcase_07 AC 146 ms
22,424 KB
testcase_08 AC 54 ms
14,336 KB
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

#include <atcoder/dsu>

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<ll> A(N);
    rep(i, N) cin >> A[i];
    ll m = *min_element(A.begin(), A.end());
    const int M = 100000;
    V<ll> cnt(M + 1, 0);
    rep(i, N) cnt[A[i]]++;
    V<V<int>> G(M + 1);
    for (int i = 1; i <= M; i++) {
        for (int j = 2 * i; j <= M; j += i) {
            G[j].push_back(i);
        }
    }
    ll ans = 0;
    V<ll> B;
    for (int i = M; i >= 1; i--) {
        if (cnt[i] == 0) continue;
        ans += i * (cnt[i] - 1);
        int ok = 0;
        for (auto d : G[i]) {
            if (cnt[d] != 0) {
                ok = 1;
                break;
            }
        }
        if (ok) {
            ans += i;
        } else {
            B.push_back(i);
        }
    }
    show(B, ans);
    int N2 = B.size();
    V<pair<ll, pair<int, int>>> es;
    rep(i, N2) {
        rep(j, i) { es.push_back({lcm(B[i], B[j]), {i, j}}); }
    }
    sort(es.begin(), es.end());
    atcoder::dsu uf(N2);
    for (auto [cost, p] : es) {
        if (!uf.same(p.first, p.second)) {
            uf.merge(p.first, p.second);
            ans += cost;
        }
    }
    cout << ans << '\n';
    return 0;
}
0