結果

問題 No.1917 LCMST
ユーザー ruthenruthen
提出日時 2022-04-29 23:44:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,320 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 210,916 KB
実行使用メモリ 14,656 KB
最終ジャッジ日時 2023-09-11 15:25:43
合計ジャッジ時間 11,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
14,380 KB
testcase_01 AC 48 ms
14,400 KB
testcase_02 AC 48 ms
14,656 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 48 ms
14,448 KB
testcase_09 TLE -
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);
    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