結果

問題 No.2756 GCD Teleporter
ユーザー aradarad
提出日時 2024-05-10 22:28:28
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,540 bytes
コンパイル時間 5,116 ms
コンパイル使用メモリ 328,632 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-05-10 22:28:46
合計ジャッジ時間 15,945 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 20 ms
6,940 KB
testcase_05 AC 85 ms
6,944 KB
testcase_06 AC 242 ms
6,940 KB
testcase_07 AC 199 ms
6,940 KB
testcase_08 AC 197 ms
6,940 KB
testcase_09 AC 146 ms
6,944 KB
testcase_10 AC 216 ms
6,944 KB
testcase_11 AC 279 ms
6,944 KB
testcase_12 AC 69 ms
6,940 KB
testcase_13 AC 365 ms
7,296 KB
testcase_14 AC 321 ms
7,168 KB
testcase_15 AC 71 ms
6,944 KB
testcase_16 AC 178 ms
6,940 KB
testcase_17 AC 209 ms
6,944 KB
testcase_18 AC 63 ms
6,944 KB
testcase_19 AC 370 ms
7,424 KB
testcase_20 AC 559 ms
6,944 KB
testcase_21 AC 249 ms
6,944 KB
testcase_22 AC 378 ms
6,940 KB
testcase_23 AC 67 ms
6,940 KB
testcase_24 AC 428 ms
6,940 KB
testcase_25 AC 450 ms
6,940 KB
testcase_26 AC 443 ms
6,940 KB
testcase_27 AC 369 ms
6,944 KB
testcase_28 AC 169 ms
6,940 KB
testcase_29 AC 257 ms
6,944 KB
testcase_30 AC 349 ms
6,940 KB
testcase_31 AC 140 ms
6,944 KB
testcase_32 AC 912 ms
6,944 KB
testcase_33 AC 342 ms
6,940 KB
testcase_34 AC 55 ms
6,944 KB
testcase_35 AC 374 ms
6,940 KB
testcase_36 AC 245 ms
6,944 KB
testcase_37 WA -
testcase_38 AC 137 ms
6,940 KB
testcase_39 AC 137 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using P = pair<ll,ll>;
using VP = vector<P>;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define out(x) cout << x << endl
#define dout(x) cout << fixed << setprecision(10) << x << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)(x.size())
#define re0 return 0
#define pcnt __builtin_popcountll
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int inf = 1e9;
constexpr ll INF = 1e18;
//using mint = modint1000000007;
using mint = modint998244353;
int di[4] = {1,0,-1,0};
int dj[4] = {0,1,0,-1};

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        res.push_back({a, ex});
    }

    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    ll n;
    cin >> n;
    VL a(n);
    rep(i,n) cin >> a[i];
    const ll mx = 1e5;
    dsu uf(n+mx);
    map<ll,ll> id;
    ll now = n;
    rep(i,n){
        VP ps = prime_factorize(a[i]);
        for(auto [c,d]:ps){
            if(id.count(c)){
                uf.merge(id[c],i);
            } else {
                id[c] = now++;
                uf.merge(id[c],i);
            }
        }
    }
    ll ans = INF;
    {
        set<ll> seen;
        bool flag = false;
        if(!id.count(2)){
            id[2] = now++;
            flag = true;
        }
        ll cnt = 0;
        rep(i,n){
            if(uf.same(id[2],i)) continue;
            if(seen.count(uf.leader(i))) continue;
            cnt++;
            seen.insert(uf.leader(i));
        }
        chmin(ans,cnt*2);
        if(flag) id.erase(2);
    }
    {
        set<ll> seen;
        ll mn = id.begin()->first;
        ll cnt = 0;
        rep(i,n){
            if(uf.same(id[mn],i)) continue;
            if(seen.count(uf.leader(i))) continue;
            cnt++;
            seen.insert(uf.leader(i));
        }
        chmin(ans,cnt*mn);
    }
    out(ans);
}
0