結果
問題 |
No.2756 GCD Teleporter
|
ユーザー |
|
提出日時 | 2024-05-11 17:10:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 821 bytes |
コンパイル時間 | 4,152 ms |
コンパイル使用メモリ | 262,504 KB |
最終ジャッジ日時 | 2025-02-21 13:40:27 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 WA * 9 |
ソースコード
#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; void chmin(int &a,int b){ if(a>b) a=b; } int main(){ int n; cin>>n; vector<int> a(n); rep(i,n) cin>>a.at(i); map<int,vector<int>> mp; rep(i,n){ int tmp=a.at(i); for(int 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<int> sc(n,1e9); for(auto&[x,v]:mp){ for(auto&y:v){ chmin(sc.at(uf.leader(y)),x); } } int mn=1e9; set<int> st; rep(i,n){ st.insert(uf.leader(i)); chmin(mn,sc.at(uf.leader(i))); } cout<<(ll)mn*(st.size()-1)<<endl; }