結果

問題 No.2756 GCD Teleporter
ユーザー 遭難者遭難者
提出日時 2024-05-10 21:00:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,014 bytes
コンパイル時間 6,585 ms
コンパイル使用メモリ 317,004 KB
実行使用メモリ 9,712 KB
最終ジャッジ日時 2024-05-10 21:00:50
合計ジャッジ時間 8,313 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 22 ms
6,944 KB
testcase_21 AC 13 ms
6,944 KB
testcase_22 AC 23 ms
6,944 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 AC 18 ms
6,940 KB
testcase_25 AC 20 ms
6,940 KB
testcase_26 AC 21 ms
6,944 KB
testcase_27 AC 22 ms
6,944 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 23 ms
6,944 KB
testcase_39 AC 22 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    int one = 0;
    bool two = false, three = false;
    for (int i : a) {
        one += i == 1;
        two |= i % 2 == 0;
        three |= i % 3 == 0;
    }
    constexpr int inf = 2e5 + 1;
    vec<int> cnt(inf);
    for (int i : a) cnt[i] = 1;
    cnt[1] = 0;
    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 m = g.size() + one;
    int ans = 2 * m;
    if (two) {
        chmin(ans, 2 * (m - 1));
    }
    if (three) {
        chmin(ans, 3 * (m - 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;
}
0