結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 64 ms
6,916 KB
testcase_11 AC 64 ms
7,040 KB
testcase_12 AC 12 ms
5,376 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 12 ms
5,376 KB
testcase_15 AC 40 ms
5,888 KB
testcase_16 AC 61 ms
7,036 KB
testcase_17 AC 24 ms
5,504 KB
testcase_18 AC 33 ms
6,020 KB
testcase_19 AC 28 ms
5,788 KB
testcase_20 AC 35 ms
6,148 KB
testcase_21 AC 27 ms
5,632 KB
testcase_22 AC 38 ms
5,892 KB
testcase_23 AC 61 ms
6,908 KB
testcase_24 AC 61 ms
7,044 KB
testcase_25 AC 59 ms
6,916 KB
testcase_26 AC 62 ms
6,944 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,744 KB
testcase_32 AC 55 ms
6,912 KB
testcase_33 AC 44 ms
6,944 KB
testcase_34 AC 44 ms
7,040 KB
testcase_35 AC 17 ms
5,376 KB
testcase_36 AC 35 ms
5,884 KB
testcase_37 AC 44 ms
6,988 KB
testcase_38 AC 40 ms
6,948 KB
testcase_39 AC 21 ms
5,504 KB
testcase_40 AC 23 ms
5,632 KB
testcase_41 AC 51 ms
6,916 KB
testcase_42 AC 50 ms
6,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i=0;i<N;i++) cin >> A[i];

    ll cnt = 0;
    vector<ll> B;
    for (int i=0;i<N;i++) {
        if (A[i] == 0) {
            cnt++;
        } else {
            B.push_back(A[i]);
        }
    }
    sort(B.begin(), B.end());
    int m = (int)B.size();

    if (m == 0) {
        cout << "Yes" << "\n";
        return 0;
    }

    bool flag = false;
    for (int i=0;i<m-1;i++) {
        if (B[i] == B[i+1]) flag = true;
    }
    if (flag) {
        for (int i=0;i<m;i++) {
            if (B[i] != B[0]) {
                cout << "No" << "\n";
                return 0;
            }
        }
        cout << "Yes" << "\n";
        return 0;
    }

    ll gcd_all = 0LL;
    for (int i=0;i<m-1;i++) {
        gcd_all = GCD(gcd_all, B[i+1]-B[i]);
    }

    ll ans = 0LL;
    for (int i=0;i<m-1;i++) {
        ans += (B[i+1]-B[i])/gcd_all-1;
    }


    if (cnt >= ans) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    return 0;
}
0