結果
| 問題 | No.2756 GCD Teleporter | 
| コンテスト | |
| ユーザー |  arad | 
| 提出日時 | 2024-05-10 22:28:28 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,540 bytes | 
| コンパイル時間 | 6,614 ms | 
| コンパイル使用メモリ | 328,244 KB | 
| 実行使用メモリ | 7,424 KB | 
| 最終ジャッジ日時 | 2024-12-20 06:22:04 | 
| 合計ジャッジ時間 | 17,863 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 35 WA * 1 | 
ソースコード
#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);
}
            
            
            
        