結果

問題 No.2756 GCD Teleporter
ユーザー MZKiMZKi
提出日時 2023-03-13 18:08:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,215 bytes
コンパイル時間 5,241 ms
コンパイル使用メモリ 270,540 KB
実行使用メモリ 7,660 KB
最終ジャッジ日時 2023-10-18 11:14:19
合計ジャッジ時間 9,426 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,956 KB
testcase_01 AC 4 ms
4,956 KB
testcase_02 AC 4 ms
4,956 KB
testcase_03 AC 4 ms
4,956 KB
testcase_04 AC 13 ms
5,220 KB
testcase_05 AC 46 ms
6,012 KB
testcase_06 AC 125 ms
7,068 KB
testcase_07 AC 101 ms
6,804 KB
testcase_08 AC 92 ms
6,540 KB
testcase_09 AC 78 ms
6,540 KB
testcase_10 AC 112 ms
6,804 KB
testcase_11 AC 145 ms
7,332 KB
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 AC 116 ms
6,804 KB
testcase_21 AC 55 ms
5,748 KB
testcase_22 AC 118 ms
6,804 KB
testcase_23 AC 18 ms
5,220 KB
testcase_24 AC 94 ms
6,276 KB
testcase_25 AC 101 ms
6,540 KB
testcase_26 AC 112 ms
6,804 KB
testcase_27 AC 120 ms
6,804 KB
testcase_28 AC 64 ms
6,012 KB
testcase_29 AC 94 ms
6,276 KB
testcase_30 AC 121 ms
6,804 KB
testcase_31 AC 54 ms
5,748 KB
testcase_32 AC 81 ms
6,540 KB
testcase_33 AC 34 ms
5,484 KB
testcase_34 AC 16 ms
5,220 KB
testcase_35 AC 86 ms
6,540 KB
testcase_36 AC 82 ms
6,540 KB
testcase_37 WA -
testcase_38 AC 141 ms
6,540 KB
testcase_39 AC 156 ms
6,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

struct smart_sieve{
	int n;
	vector<int> f;
	// 初期構築 : (nloglog(n))
	smart_sieve(int x = 1) :n(x), f(x+1, -1){
        for(ll i = 2; i <= n; i++){
            if(f[i] != -1)continue;
            for(ll j = i*i; j <= n; j += i){
                f[j] = (f[j] == -1 ? i : f[j]);
            }
            f[i] = i;
        }
	}
	// 素数判定 : O(1)
	bool isPrime(int x){return f[x] == x;}
	// 素因数分解 : O(log(n))
	vector<pair<ll,ll>> prime_factor(int x){
        if(x == 1)return {};
        vector<pair<ll, ll>> ret;
        ret.emplace_back(f[x], 1); x /= f[x];
		while(x != 1){
            if(f[x] == ret.back().first){
                ret.back().second++;
            }else{
                ret.emplace_back(f[x], 1);
            }
            x /= f[x];
        }
        return ret;
	}
};


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];

    set<int> pf;
    smart_sieve ss(200000);
    rep(i, n){
        vector<pair<ll, ll>> p;
        p = ss.prime_factor(a[i]);
        for(auto x : p)pf.insert(x.first);
    }
    
    int cnt = 0, mn = mod;
    vector<int> pos(200000, -1);
    for(auto it = pf.begin(); it != pf.end(); it++){
        mn = (mn == mod ? (*it) : mn); pos[*it] = cnt++;
    }

    dsu uf(n+cnt);
    rep(i, n){
        vector<pair<ll, ll>> p;
        p = ss.prime_factor(a[i]);
        for(auto x : p)uf.merge(i, n+pos[x.first]);
    }

    set<int> st;
    rep(i, n)st.insert(uf.leader(i));
    int ans = mod, S = st.size();
    if(pos[2] == -1){
        ans = mn*(S-1);
    }else{
        ans = 2 * (S-1);
    }
	
    cout << ans << endl;
}
0