結果

問題 No.2756 GCD Teleporter
ユーザー 遭難者遭難者
提出日時 2024-05-10 21:18:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 2,943 bytes
コンパイル時間 5,521 ms
コンパイル使用メモリ 316,908 KB
実行使用メモリ 9,580 KB
最終ジャッジ日時 2024-05-10 21:18:32
合計ジャッジ時間 8,794 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 5 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 29 ms
6,944 KB
testcase_06 AC 58 ms
8,940 KB
testcase_07 AC 50 ms
8,108 KB
testcase_08 AC 48 ms
7,912 KB
testcase_09 AC 43 ms
7,432 KB
testcase_10 AC 54 ms
8,720 KB
testcase_11 AC 61 ms
9,580 KB
testcase_12 AC 16 ms
6,944 KB
testcase_13 AC 39 ms
8,320 KB
testcase_14 AC 36 ms
8,320 KB
testcase_15 AC 16 ms
6,944 KB
testcase_16 AC 29 ms
6,944 KB
testcase_17 AC 30 ms
7,424 KB
testcase_18 AC 16 ms
6,940 KB
testcase_19 AC 41 ms
8,448 KB
testcase_20 AC 30 ms
6,944 KB
testcase_21 AC 20 ms
6,944 KB
testcase_22 AC 30 ms
6,944 KB
testcase_23 AC 10 ms
6,944 KB
testcase_24 AC 27 ms
6,940 KB
testcase_25 AC 27 ms
6,944 KB
testcase_26 AC 29 ms
6,940 KB
testcase_27 AC 30 ms
6,940 KB
testcase_28 AC 24 ms
6,944 KB
testcase_29 AC 31 ms
7,040 KB
testcase_30 AC 38 ms
7,552 KB
testcase_31 AC 22 ms
6,940 KB
testcase_32 AC 25 ms
6,940 KB
testcase_33 AC 12 ms
6,940 KB
testcase_34 AC 8 ms
6,944 KB
testcase_35 AC 23 ms
6,944 KB
testcase_36 AC 21 ms
6,940 KB
testcase_37 AC 5 ms
6,940 KB
testcase_38 AC 25 ms
6,944 KB
testcase_39 AC 25 ms
6,944 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 + 2024;
    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;
    }
    atcoder::dsu d(n);
    for (int i = 2; i < inf; i++) {
        vec<int> p;
        for (int j = i; j < inf; j += i) {
            if (cnt[j] != -1) p.push_back(cnt[j]);
        }
        for (int j = 1; j < p.size(); j++) {
            d.merge(p[0], p[j]);
        }
    }
    auto g = d.groups();
    int m = g.size() + one;
    if (m == 1) {
        cout << 0 << endl;
        return;
    }
    if (two) {
        cout << 2 * (m - 1) << endl;
        return;
    }
    int ans = 2 * m;
    if (three)
        chmin(ans, 3 * (m - 1));
    cout << ans << endl;
    return;
}
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