結果

問題 No.1917 LCMST
ユーザー Dispersion-atcDispersion-atc
提出日時 2024-03-01 02:43:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,450 bytes
コンパイル時間 2,841 ms
コンパイル使用メモリ 211,508 KB
実行使用メモリ 28,768 KB
最終ジャッジ日時 2024-03-01 02:43:51
合計ジャッジ時間 29,204 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,676 KB
testcase_01 AC 6 ms
6,676 KB
testcase_02 AC 7 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 6 ms
6,676 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 631 ms
28,768 KB
testcase_30 AC 662 ms
28,768 KB
testcase_31 AC 635 ms
28,640 KB
testcase_32 AC 656 ms
28,640 KB
testcase_33 AC 632 ms
28,768 KB
testcase_34 AC 280 ms
14,308 KB
testcase_35 AC 280 ms
14,308 KB
testcase_36 AC 304 ms
14,308 KB
testcase_37 AC 638 ms
28,640 KB
testcase_38 AC 642 ms
28,640 KB
testcase_39 AC 665 ms
28,640 KB
testcase_40 AC 647 ms
28,640 KB
testcase_41 AC 637 ms
28,768 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T>
bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0;}

using ll = long long;
const ll amax = 1e5 + 100;

ll gcd(ll a, ll b)
{
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

int main()
{
    ll N; cin >> N;
    vector<ll> A(N);
    for (auto &a : A) cin >> a;
    
    vector<ll> uniq;
    vector<ll> cnt(amax, 0);
    ll res = 0;
    for (auto a : A)
    {
        if (cnt[a] == 0) uniq.emplace_back(a);
        else res += a;
        cnt[a] += 1;
    }
    
    sort(uniq.begin(), uniq.end());
    vector<vector<ll>> vec(amax);
    const ll INF = 1e18;
    for (auto a : uniq)
    {
        vector<ll> divisor;
        for (int i = 1; i * i <= a; ++i)
        {
            if (a % i == 0)
            {
                divisor.emplace_back(i);
                if (a / i != i) divisor.emplace_back(a / i);
            }
        }
        
        ll mn = INF;
        for (auto d : divisor)
        {
            if (vec[d].size() == 0)
            {
                vec[d].emplace_back(a);
                continue;
            }
            ll t = vec[d][0];
            chmin(mn, lcm(a, t));
            
            vec[d].emplace_back(a);
        }
        // cout << a << " " << mn << endl;
        if (mn == INF) continue;
        res += mn;
    }
    cout << res << endl;
    
    return 0;
}
0