結果
| 問題 |
No.2756 GCD Teleporter
|
| コンテスト | |
| ユーザー |
遭難者
|
| 提出日時 | 2024-05-10 20:58:34 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,961 bytes |
| コンパイル時間 | 7,067 ms |
| コンパイル使用メモリ | 316,640 KB |
| 実行使用メモリ | 9,596 KB |
| 最終ジャッジ日時 | 2024-12-20 04:13:36 |
| 合計ジャッジ時間 | 9,852 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 WA * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using mint = atcoder::modint1000000007;
istream& operator>>(istream& is, mint& a) {
int t; is >> t; a = t;
return is;
}
ostream& operator<<(ostream& os, mint a) {
return os << a.val();
}
#endif
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#else
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#define cerr if (false) cerr
#undef endl
#define endl '\n'
#endif
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
#define vec vector
#undef long
#define long long long
template<typename T>
ostream& operator<<(ostream& os, vector<T> a) {
const int n = a.size();
rep(i, n) os << a[i] << " \n"[i + 1 == n];
return os;
}
template<typename T, size_t n>
ostream& operator<<(ostream& os, array<T, n> a) {
rep(i, n) os << a[i] << " \n"[i + 1 == n];
return os;
}
template<typename T>
istream& operator>>(istream& is, vector<T>& a) {
for (T& i : a) is >> i;
return is;
}
template<typename T>
bool chmin(T& x, T y) {
if (x > y) { x = y; return true; }
return false;
}
template<typename T>
bool chmax(T& x, T y) {
if (x < y) { x = y; return true; }
return false;
}
template<typename T>
void operator++(vector<T>& a) {
for (T& i : a) ++i;
}
template<typename T>
void operator--(vector<T>& a) {
for (T& i : a) --i;
}
template<typename T>
void operator++(vector<T>& a, int) {
for (T& i : a) i++;
}
template<typename T>
void operator--(vector<T>& a, int) {
for (T& i : a) i--;
}
void solve()
{
int n; cin >> n;
vec<int> a(n); cin >> a;
bool two = false, three = false;
for (int i : a) {
two |= i % 2 == 0;
three |= i % 3 == 0;
}
constexpr int inf = 2e5 + 1;
vec<int> cnt(inf);
for (int i : a) cnt[i] = 1;
a.clear();
for (int i = 0; i < inf; i++) if (cnt[i]) a.push_back(i);
n = a.size();
fill(ALL(cnt), -1);
for (int i = 0; i < n; i++) {
cnt[a[i]] = i;
}
vec<bool> prime(inf, true);
prime[0] = prime[1] = false;
atcoder::dsu d(n);
for (int i = 2; i * i < inf; i++) {
if (prime[i]) {
vec<int> p;
for (int j = i; j < inf; j += i) {
if (cnt[j] != -1) p.push_back(cnt[j]);
prime[j] = false;
}
for (int j = 1; j < p.size(); j++) {
d.merge(p[0], p[j]);
}
}
}
auto g = d.groups();
int ans = 2 * g.size();
if (two) {
chmin(ans, 2 * (int)(g.size() - 1));
}
if (three) {
chmin(ans, 3 * (int)(g.size() - 1));
}
cout << ans << endl;
}
int main()
{
srand((unsigned)time(NULL));
cin.tie(nullptr);
ios::sync_with_stdio(false);
// cout << fixed << setprecision(40);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
遭難者