結果

問題 No.1884 Sequence
ユーザー NoviNovi
提出日時 2022-03-25 21:50:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,860 bytes
コンパイル時間 3,871 ms
コンパイル使用メモリ 238,028 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2023-08-04 08:43:10
合計ジャッジ時間 9,492 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 141 ms
17,152 KB
testcase_11 AC 136 ms
17,100 KB
testcase_12 AC 452 ms
4,424 KB
testcase_13 AC 398 ms
4,400 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define int ll
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define ALL(a) (a).begin(), (a).end()
template <class t, class u> void chmax(t& a, u b) {
    if (a < b) a = b;
}
template <class t, class u> void chmin(t& a, u b) {
    if (b < a) a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
using uint = unsigned;
using ull = unsigned long long;
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }
ll mask(int i) { return (ll(1) << i) - 1; }
int lcm(int a, int b) { return a / __gcd(a, b) * b; }
vector<int> enum_divisors(int N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N / i != i) res.push_back(N / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vc<int> a(n);
    set<int> prime;
    rep(i, n) cin >> a[i];
    set<int> elem;
    rep(i, n) elem.insert(a[i]);
    if (elem.size() <= 2) {
        cout << "Yes" << endl;
        return 0;
    }
    // dを全探索したい
    int cnt = 0;
    vc<int> b;
    rep(i, n) {
        if (a[i] == 0)
            cnt++;
        else {
            b.emplace_back(a[i]);
        }
    }
    vc<int> ma = b;
    sort(ALL(ma));
    if (cnt == 0) {
        bool ok = true;
        int x = ma[1] - ma[0];
        rep(i, n - 1) if (ma[i + 1] - ma[i] != x) ok = false;
        if (ok) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        return 0;
    }
    bool same = false;
    rep(i, ma.size() - 1) {
        if (ma[i] == ma[i + 1]) same = true;
    }
    if (same) {
        rep(i, ma.size() - 1) {
            if (ma[i] != ma[i + 1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    for (int i = 0; i < b.size() - 1; i++) {
        int diff = ma[i + 1] - ma[i];
        auto q = enum_divisors(diff);
        for (auto u : q) prime.insert(u);
    }
    vc<int> d(ALL(prime));
    int l = b.size();
    for (auto v : d) {
        int tmp = 0;
        bool f = true;
        for (int i = 0; i < l - 1; i++) {
            int diff = ma[i + 1] - ma[i];
            if (diff % v != 0) {
                f = false;
            } else {
                tmp += diff / v - 1;
            }
        }
        if (f && tmp <= cnt) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
0