結果

問題 No.1884 Sequence
ユーザー ぷらぷら
提出日時 2022-03-25 21:53:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 2,695 ms
コンパイル使用メモリ 201,460 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 06:34:46
合計ジャッジ時間 7,271 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 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 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 144 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 30 ms
5,376 KB
testcase_13 AC 32 ms
5,376 KB
testcase_14 AC 30 ms
5,376 KB
testcase_15 AC 92 ms
5,376 KB
testcase_16 AC 143 ms
5,376 KB
testcase_17 AC 63 ms
5,376 KB
testcase_18 AC 89 ms
5,376 KB
testcase_19 AC 72 ms
5,376 KB
testcase_20 AC 78 ms
5,376 KB
testcase_21 AC 60 ms
5,376 KB
testcase_22 AC 85 ms
5,376 KB
testcase_23 AC 143 ms
5,376 KB
testcase_24 AC 143 ms
5,376 KB
testcase_25 AC 137 ms
5,376 KB
testcase_26 AC 141 ms
5,376 KB
testcase_27 AC 36 ms
5,376 KB
testcase_28 AC 36 ms
5,376 KB
testcase_29 AC 36 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 75 ms
5,376 KB
testcase_32 AC 135 ms
5,376 KB
testcase_33 AC 127 ms
5,376 KB
testcase_34 AC 127 ms
5,376 KB
testcase_35 AC 42 ms
5,376 KB
testcase_36 AC 97 ms
5,376 KB
testcase_37 AC 126 ms
5,376 KB
testcase_38 AC 113 ms
5,376 KB
testcase_39 AC 54 ms
5,376 KB
testcase_40 AC 59 ms
5,376 KB
testcase_41 AC 116 ms
5,376 KB
testcase_42 AC 116 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long gcd2(long long a,long long b) {
    if(a == 0 || b == 0) {
        return max(a,b);
    }
    if(a % b == 0) {
        return b;
    }
    else {
        return gcd2(b,a % b);
    }
}

int main() {
    int N;
    cin >> N;
    vector<long long>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    long long g = -1;
    for(int i = 0; i+1 < N; i++) {
        if(A[i] == 0) {
            continue;
        }
        if(g == -1) {
            g = A[i+1]-A[i];
        }
        else if(g == 0 || A[i+1]-A[i] == 0) {
            if(g == 0 && A[i+1]-A[i] == 0) {
                continue;
            }
            cout << "No" << endl;
            return 0;
        }
        else {
            g = gcd2(g,A[i+1]-A[i]);
        }
    }
    if(g == 0 || g == -1) {
        cout << "Yes" << endl;
    }
    else {
        int ans = 0;
        for(int i = 0; i+1 < N; i++) {
            if(A[i] == 0) {
                ans--;
            }
            else {
                ans += (A[i+1]-A[i])/g-1;
            }
        }
        cout << ((ans <= 0)?"Yes":"No") << endl;
    }
}
0