結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,952 KB
testcase_01 AC 4 ms
4,952 KB
testcase_02 WA -
testcase_03 AC 4 ms
4,952 KB
testcase_04 AC 13 ms
5,216 KB
testcase_05 AC 45 ms
6,008 KB
testcase_06 AC 122 ms
7,064 KB
testcase_07 AC 100 ms
6,800 KB
testcase_08 AC 90 ms
6,536 KB
testcase_09 AC 78 ms
6,536 KB
testcase_10 AC 109 ms
6,800 KB
testcase_11 AC 142 ms
7,328 KB
testcase_12 AC 29 ms
5,800 KB
testcase_13 AC 139 ms
7,592 KB
testcase_14 AC 128 ms
7,592 KB
testcase_15 AC 31 ms
5,812 KB
testcase_16 AC 73 ms
6,800 KB
testcase_17 AC 89 ms
7,064 KB
testcase_18 AC 29 ms
5,768 KB
testcase_19 AC 143 ms
7,592 KB
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 AC 63 ms
6,008 KB
testcase_29 AC 93 ms
6,272 KB
testcase_30 AC 121 ms
6,800 KB
testcase_31 AC 53 ms
5,744 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 15 ms
5,216 KB
testcase_35 AC 85 ms
6,536 KB
testcase_36 AC 82 ms
6,536 KB
testcase_37 AC 4 ms
4,952 KB
testcase_38 AC 141 ms
6,536 KB
testcase_39 AC 159 ms
6,536 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 = 2*S;
    }else{
        ans = 2 * (S-1);
    }
	
    cout << ans << endl;
}
0