結果

問題 No.1917 LCMST
ユーザー daddydaddy
提出日時 2023-06-29 00:05:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 763 ms / 4,000 ms
コード長 3,193 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 179,652 KB
実行使用メモリ 94,588 KB
最終ジャッジ日時 2023-09-19 04:58:00
合計ジャッジ時間 25,914 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,068 KB
testcase_01 AC 6 ms
6,956 KB
testcase_02 AC 6 ms
6,900 KB
testcase_03 AC 8 ms
7,220 KB
testcase_04 AC 8 ms
7,276 KB
testcase_05 AC 8 ms
7,272 KB
testcase_06 AC 8 ms
7,252 KB
testcase_07 AC 8 ms
7,252 KB
testcase_08 AC 5 ms
6,904 KB
testcase_09 AC 662 ms
72,060 KB
testcase_10 AC 655 ms
72,240 KB
testcase_11 AC 649 ms
71,268 KB
testcase_12 AC 565 ms
63,352 KB
testcase_13 AC 360 ms
32,912 KB
testcase_14 AC 599 ms
67,664 KB
testcase_15 AC 311 ms
24,328 KB
testcase_16 AC 371 ms
33,372 KB
testcase_17 AC 428 ms
53,176 KB
testcase_18 AC 472 ms
53,420 KB
testcase_19 AC 327 ms
23,808 KB
testcase_20 AC 297 ms
19,960 KB
testcase_21 AC 330 ms
24,804 KB
testcase_22 AC 300 ms
19,980 KB
testcase_23 AC 300 ms
19,892 KB
testcase_24 AC 328 ms
24,160 KB
testcase_25 AC 300 ms
20,212 KB
testcase_26 AC 310 ms
21,364 KB
testcase_27 AC 314 ms
23,036 KB
testcase_28 AC 318 ms
23,172 KB
testcase_29 AC 743 ms
94,212 KB
testcase_30 AC 760 ms
94,588 KB
testcase_31 AC 757 ms
94,412 KB
testcase_32 AC 763 ms
94,584 KB
testcase_33 AC 763 ms
94,216 KB
testcase_34 AC 268 ms
14,780 KB
testcase_35 AC 269 ms
14,596 KB
testcase_36 AC 267 ms
14,560 KB
testcase_37 AC 761 ms
94,176 KB
testcase_38 AC 752 ms
94,212 KB
testcase_39 AC 749 ms
94,216 KB
testcase_40 AC 746 ms
94,412 KB
testcase_41 AC 741 ms
94,416 KB
testcase_42 AC 723 ms
94,532 KB
testcase_43 AC 271 ms
15,312 KB
testcase_44 AC 271 ms
15,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
using dvec = vector<double>;
using dmat = vector<dvec>;

#define INF (1LL<<61)
#define MOD 1000000007LL 
//#define MOD 998244353LL

#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORE(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) {ASC((x)); REV((x));}
#define BIT(s,i) (((s)>>(i))&1)
#define pb push_back
#define fi first
#define se second

class mint {
public:
    ll x;
    mint(ll x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {return mint(-x);}
    mint& operator+=(const mint& a) {if((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint& operator-=(const mint& a) {if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint& operator*=(const mint& a) {(x*=a.x)%=MOD; return *this;}
    mint operator+(const mint& a) const {mint b(*this); return b+=a;}
    mint operator-(const mint& a) const {mint b(*this); return b-=a;}
    mint operator*(const mint& a) const {mint b(*this); return b*=a;}
    mint pow(ll t) const {if(!t) return 1; mint a=pow(t>>1); return (t&1?*this*a:a)*a;}
    mint inv() const {return pow(MOD-2);}
    mint& operator/=(const mint& a) {return *this*=a.inv();}
    mint operator/(const mint& a) const {mint b(*this); return b/=a;}
};
istream &operator>>(istream& is, mint& a) {ll t; is>>t; a=t; return is;}
ostream &operator<<(ostream& os, const mint& a) {return os<<a.x;}
using mvec = vector<mint>;
using mmat = vector<mvec>;

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

struct UnionFind {
    
    vec par;
    vec rank;
    vec num;
    
    UnionFind(ll N) {
        par = vec(N);
        REP(i,0,N) par[i] = i;
        rank = vec(N, 0);
        num = vec(N, 1);
    }

    ll root(ll x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    } 

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return;
        if(rank[rx] < rank[ry]) swap(rx, ry);
        par[ry] = rx;
        num[rx] += num[ry];
        if(rank[rx] == rank[ry]) ++rank[rx];
    }

    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return num[root(x)];
    }

};

int main()
{  
    ll N;
    cin >> N;
    vec A(N);
    REP(i,0,N) cin >> A[i];

    ll ans = 0, M = 100010;
    vec C(M), D(M, -1);
    FORE(i,A) {
        if(C[i] == 0) C[i] = 1;
        else ans += i;
    }
    
    mat E;
    REP(i,1,M) {
        for(ll j=i; j<M; j+=i) {
            if(C[j] == 1) {
                if(D[i] == -1) D[i] = j;
                else E.pb({D[i]*j/i, D[i], j});
            }
        }
    }
    ASC(E);

    UnionFind uf(M);
    FORE(e,E) {
        if(!uf.same(e[1], e[2])) {
            ans += e[0];
            uf.unite(e[1], e[2]);
        }
    }

    PR(ans);

    return 0;
}

/*



*/
0