結果
問題 | No.2756 GCD Teleporter |
ユーザー |
|
提出日時 | 2024-05-11 17:25:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 981 ms / 2,000 ms |
コード長 | 850 bytes |
コンパイル時間 | 4,161 ms |
コンパイル使用メモリ | 265,180 KB |
最終ジャッジ日時 | 2025-02-21 13:41:22 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) using mint = atcoder::modint998244353; template<class T> void chmin(T &a,T b){ if(a>b) a=b; } int main(){ int n; cin>>n; vector<int> a(n); rep(i,n) cin>>a.at(i); map<ll,vector<int>> mp; rep(i,n){ int tmp=a.at(i); for(ll j=2;j*j<=tmp;j++){ if(tmp%j==0){ mp[j].push_back(i); while(tmp%j==0) tmp/=j; } } if(tmp>1) mp[tmp].push_back(i); } atcoder::dsu uf(n); for(auto&[x,v]:mp){ for(auto&y:v){ uf.merge(v.at(0),y); } } vector<ll> sc(n,1e18); for(auto&[x,v]:mp){ for(auto&y:v){ chmin(sc.at(uf.leader(y)),x); } } ll mn=1e18; set<int> st; rep(i,n){ st.insert(uf.leader(i)); chmin(mn,sc.at(uf.leader(i))); } cout<<min((ll)2*st.size(),mn*(st.size()-1))<<endl; }