結果

問題 No.1884 Sequence
ユーザー hourenhouren
提出日時 2022-03-25 21:34:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 170,008 KB
実行使用メモリ 7,908 KB
最終ジャッジ日時 2024-04-22 06:12:24
合計ジャッジ時間 4,548 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 61 ms
7,776 KB
testcase_11 AC 61 ms
7,780 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 38 ms
5,600 KB
testcase_16 AC 60 ms
7,904 KB
testcase_17 AC 23 ms
5,376 KB
testcase_18 AC 32 ms
5,728 KB
testcase_19 AC 26 ms
5,472 KB
testcase_20 AC 32 ms
5,480 KB
testcase_21 AC 24 ms
5,376 KB
testcase_22 AC 35 ms
5,376 KB
testcase_23 AC 60 ms
7,780 KB
testcase_24 AC 61 ms
7,780 KB
testcase_25 AC 60 ms
7,904 KB
testcase_26 AC 61 ms
7,908 KB
testcase_27 AC 13 ms
5,376 KB
testcase_28 AC 13 ms
5,376 KB
testcase_29 AC 13 ms
5,376 KB
testcase_30 AC 13 ms
5,376 KB
testcase_31 AC 31 ms
5,376 KB
testcase_32 AC 58 ms
7,780 KB
testcase_33 AC 43 ms
5,472 KB
testcase_34 AC 43 ms
5,376 KB
testcase_35 AC 15 ms
5,376 KB
testcase_36 AC 32 ms
5,376 KB
testcase_37 AC 46 ms
7,776 KB
testcase_38 AC 42 ms
7,908 KB
testcase_39 AC 20 ms
5,376 KB
testcase_40 AC 22 ms
5,376 KB
testcase_41 AC 50 ms
7,396 KB
testcase_42 AC 50 ms
7,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
ll gcd(ll x, ll y){
    if(x>y) swap(x,y);
    if(!x) return 0;
    if(y%x) return gcd(y%x,x);
    return x;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,cnt = 0;
    cin >> n;
    vector<ll> a,d;
    rep(i,n){
        ll x;
        cin >> x;
        if(x) a.push_back(x);
        else cnt++;
    }
    sort(all(a));
    if(n-1<=cnt || a[n-cnt-1]-a[0]==0){
        cout << "Yes\n";
        return 0;
    }
    rep(i,n-cnt-1) d.push_back(a[i+1]-a[i]);
    ll g = d[0];
    rep(i,n-cnt-2) g = gcd(g,d[i+1]);
    if(g && (a[n-cnt-1]-a[0])/g<=n-1) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}
0