結果

問題 No.1884 Sequence
ユーザー ruthenruthen
提出日時 2022-03-25 21:53:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 2,364 ms
コンパイル使用メモリ 201,488 KB
実行使用メモリ 7,044 KB
最終ジャッジ日時 2024-04-22 06:33:28
合計ジャッジ時間 5,156 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 66 ms
7,040 KB
testcase_11 AC 65 ms
6,908 KB
testcase_12 AC 12 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 12 ms
5,376 KB
testcase_15 AC 39 ms
6,016 KB
testcase_16 AC 61 ms
6,912 KB
testcase_17 AC 24 ms
5,504 KB
testcase_18 AC 31 ms
6,016 KB
testcase_19 AC 27 ms
5,660 KB
testcase_20 AC 33 ms
6,016 KB
testcase_21 AC 25 ms
5,376 KB
testcase_22 AC 35 ms
6,016 KB
testcase_23 AC 60 ms
6,944 KB
testcase_24 AC 60 ms
6,944 KB
testcase_25 AC 57 ms
7,040 KB
testcase_26 AC 58 ms
7,040 KB
testcase_27 AC 14 ms
5,376 KB
testcase_28 AC 14 ms
5,376 KB
testcase_29 AC 14 ms
5,376 KB
testcase_30 AC 14 ms
5,376 KB
testcase_31 AC 31 ms
5,740 KB
testcase_32 AC 56 ms
7,040 KB
testcase_33 AC 45 ms
7,044 KB
testcase_34 AC 45 ms
7,040 KB
testcase_35 AC 17 ms
5,376 KB
testcase_36 AC 36 ms
6,016 KB
testcase_37 AC 45 ms
7,036 KB
testcase_38 AC 41 ms
7,036 KB
testcase_39 AC 21 ms
5,504 KB
testcase_40 AC 23 ms
5,504 KB
testcase_41 AC 50 ms
6,912 KB
testcase_42 AC 51 ms
6,912 KB
権限があれば一括ダウンロードができます

ソースコード

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