結果

問題 No.1917 LCMST
ユーザー ruthen71
提出日時 2022-04-29 23:44:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,320 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 204,668 KB
最終ジャッジ日時 2025-01-29 00:26:23
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 12 TLE * 16
権限があれば一括ダウンロードができます

ソースコード

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);
    sort(B.begin(), B.end());
    int N2 = B.size();
    for (int i = N2 - 1; i >= 1; i--) {
        ll cm = 1LL << 60;
        for (int j = i - 1; j >= 0; j--) cm = min(cm, lcm(B[i], B[j]));
        ans += cm;
    }
    cout << ans << '\n';
    return 0;
}
0