結果

問題 No.1884 Sequence
ユーザー ruthen71
提出日時 2022-03-25 21:53:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 2,430 ms
コンパイル使用メモリ 200,252 KB
最終ジャッジ日時 2025-01-28 12:00:25
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<ll> A(N);
    rep(i, N) cin >> A[i];
    V<ll> B;
    rep(i, N) {
        if (A[i] != 0) B.push_back(A[i]);
    }
    int M = B.size();
    int c = N - M;
    sort(B.begin(), B.end());
    int ok = 1;
    rep(i, M - 1) {
        if (B[i] == B[i + 1]) {
            ok = 0;
        }
    }
    if (ok == 0) {
        // check
        int ok2 = 1;
        rep(i, M) {
            if (B[0] != B[i]) ok2 = 0;
        }
        cout << (ok2 ? "Yes" : "No") << '\n';
        return 0;
    }
    if (M <= 1) {
        cout << "Yes" << '\n';
        return 0;
    }
    // M >= 2
    ll g = B[1] - B[0];
    rep(i, M - 1) g = gcd(g, B[i + 1] - B[i]);
    ll c2 = 0;
    rep(i, M - 1) {
        c2 += (B[i + 1] - B[i]) / g - 1;
        if (c2 > c) {
            ok = 0;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << '\n';
    return 0;
}
0