結果

問題 No.1884 Sequence
ユーザー maguromaguro
提出日時 2022-03-25 21:32:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,618 bytes
コンパイル時間 2,502 ms
コンパイル使用メモリ 201,692 KB
実行使用メモリ 5,712 KB
最終ジャッジ日時 2024-04-22 06:08:50
合計ジャッジ時間 7,084 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 WA -
testcase_10 AC 150 ms
5,456 KB
testcase_11 AC 150 ms
5,580 KB
testcase_12 AC 25 ms
5,376 KB
testcase_13 AC 27 ms
5,376 KB
testcase_14 AC 26 ms
5,376 KB
testcase_15 AC 88 ms
5,376 KB
testcase_16 AC 143 ms
5,580 KB
testcase_17 AC 59 ms
5,376 KB
testcase_18 AC 87 ms
5,376 KB
testcase_19 AC 69 ms
5,376 KB
testcase_20 AC 75 ms
5,376 KB
testcase_21 AC 58 ms
5,376 KB
testcase_22 AC 82 ms
5,376 KB
testcase_23 AC 145 ms
5,576 KB
testcase_24 AC 145 ms
5,712 KB
testcase_25 AC 140 ms
5,456 KB
testcase_26 AC 143 ms
5,452 KB
testcase_27 AC 31 ms
5,376 KB
testcase_28 AC 31 ms
5,376 KB
testcase_29 AC 31 ms
5,376 KB
testcase_30 AC 32 ms
5,376 KB
testcase_31 AC 74 ms
5,376 KB
testcase_32 WA -
testcase_33 AC 127 ms
5,580 KB
testcase_34 AC 129 ms
5,580 KB
testcase_35 AC 37 ms
5,376 KB
testcase_36 AC 93 ms
5,376 KB
testcase_37 AC 130 ms
5,452 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 116 ms
5,448 KB
testcase_42 AC 115 ms
5,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
constexpr int Inf = 2000000000;
constexpr long long INF= 2000000000000000000;

template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T,typename U>
T modpow(T N, U P, T M = -1) {
    if(P < 0) return 0;
    T ret = 1;
    if(M != -1) ret %= M;
    while(P) {
        if(P & 1) {
            if(M == -1) ret *= N;
            else ret = ret * N % M;
        }
        P /= 2;
        if(M == -1) N *= N;
        else N = N * N % M;
    }
    return ret;
}

constexpr long long MOD = 998244353;

int main() {
    int n;
    cin >> n;
    vector<long long> vec;
    long long free_card = 0;
    for(int i = 0;i < n;i++) {
        long long a;
        cin >> a;
        if(a != 0) vec.push_back(a);
        else free_card++;
    }

    sort(vec.begin(),vec.end());
    if(free_card >= n - 1) {
        cout << "Yes" << endl;
        return 0;
    }

    long long min_gcd = vec[1] - vec[0];
    for(int i = 1;i < vec.size() - 1;i++) {
        min_gcd = gcd(min_gcd,vec[i + 1] - vec[i]);
    }

    if(min_gcd == 0) {
        if(all_of(vec.begin(),vec.end(),[&](long long a){return a == vec[0];})) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }

    long long free_count = 0;
    for(int i = 0;i < vec.size() - 1;i++) {
        free_count += (vec[i + 1] - vec[i]) / min_gcd - 1;
    }

    if(free_count <= free_card) cout << "Yes" << endl;
    else cout << "No" << endl;
}
0