結果

問題 No.1884 Sequence
ユーザー maguromaguro
提出日時 2022-03-25 21:29:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,612 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 201,436 KB
実行使用メモリ 5,584 KB
最終ジャッジ日時 2024-04-22 06:04:57
合計ジャッジ時間 6,718 ms
ジャッジサーバーID
(参考情報)
judge3 / 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 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 137 ms
5,452 KB
testcase_11 AC 138 ms
5,580 KB
testcase_12 AC 23 ms
5,376 KB
testcase_13 AC 25 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 78 ms
5,376 KB
testcase_16 AC 127 ms
5,452 KB
testcase_17 AC 60 ms
5,376 KB
testcase_18 AC 78 ms
5,376 KB
testcase_19 AC 62 ms
5,376 KB
testcase_20 AC 64 ms
5,376 KB
testcase_21 AC 49 ms
5,376 KB
testcase_22 AC 71 ms
5,376 KB
testcase_23 AC 132 ms
5,420 KB
testcase_24 AC 132 ms
5,448 KB
testcase_25 AC 121 ms
5,576 KB
testcase_26 AC 126 ms
5,376 KB
testcase_27 AC 29 ms
5,376 KB
testcase_28 AC 29 ms
5,376 KB
testcase_29 AC 28 ms
5,376 KB
testcase_30 AC 27 ms
5,376 KB
testcase_31 AC 66 ms
5,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 123 ms
5,452 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 101 ms
5,448 KB
testcase_42 AC 102 ms
5,376 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(),[&](int 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