結果

問題 No.1884 Sequence
ユーザー NoviNovi
提出日時 2022-03-25 21:35:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,743 bytes
コンパイル時間 4,633 ms
コンパイル使用メモリ 239,084 KB
実行使用メモリ 26,008 KB
最終ジャッジ日時 2023-08-04 08:24:54
合計ジャッジ時間 9,743 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,404 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 421 ms
4,648 KB
testcase_08 AC 419 ms
4,668 KB
testcase_09 WA -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
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, mb = b;
    sort(ALL(ma));
    sort(ALL(mb), greater<int>());
    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;
        }
    }
    for (auto v : d) {
        int tmp = 0;
        bool f = true;
        for (int i = 0; i < l - 1; i++) {
            int diff = mb[i] - mb[i + 1];
            if (diff % v != 0) {
                f = false;
            } else {
                tmp += diff / v - 1;
            }
        }
        if (f && tmp <= cnt) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
0