結果
問題 |
No.2756 GCD Teleporter
|
ユーザー |
![]() |
提出日時 | 2024-05-10 22:46:31 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,811 bytes |
コンパイル時間 | 6,762 ms |
コンパイル使用メモリ | 333,116 KB |
実行使用メモリ | 25,284 KB |
最終ジャッジ日時 | 2024-12-20 06:43:45 |
合計ジャッジ時間 | 12,320 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 WA * 5 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; vector<i64> erathosthenes(i64 N) { vector<i64> is_prime(N + 1, 1); is_prime[0] = is_prime[1] = 0; vector<i64> ret; for (i64 i = 2; i <= N; i++) { if (!is_prime[i]) continue; ret.push_back(i); for (i64 j = i; j <= N; j += i) { is_prime[j] = 0; } } return ret; } int main() { FAST_IO int N; cin >> N; vector<i64> A(N); for (auto &v : A) cin >> v; auto primes = erathosthenes(300000); vector<vector<i64>> ps(N); set<i64> st; i64 one = 0; for (int i = 0; i < N; i++) { auto v = A[i]; if (v == 1) { one ++; continue; } for (auto p : primes) { if (p * p > v) break; if (v % p == 0) { while (v % p == 0) { v /= p; } ps[i].push_back(p); st.insert(p); } } if (v > 1) { ps[i].push_back(v); st.insert(v); } } int m = st.size(); vector<i64> a(st.begin(), st.end()); map<i64, int> ia; ranges::sort(a); for (int i = 0; i < m; i++) { ia[a[i]] = i; } atcoder::dsu ds(m); for (int i = 0; i < N; i++) { for (int j = 0; j < ps[i].size(); j++) { ds.merge(ia[ps[i][0]], ia[ps[i][j]]); } } vector<i64> b; for (int i = 0; i < m; i++) { if (ds.leader(i) == i) { b.push_back(a[i]); } } if (b.size() == 0) { cout << one * 2 << endl; return 0; } i64 x = b.size() + one; i64 y = b[0]; i64 ans = min(x * 2LL, (x - 1) * y); cout << ans << endl; }