結果

問題 No.1884 Sequence
ユーザー hourenhouren
提出日時 2022-03-25 21:34:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 171,692 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2023-08-04 08:23:05
合計ジャッジ時間 4,964 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 54 ms
7,828 KB
testcase_11 AC 54 ms
7,708 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 35 ms
5,504 KB
testcase_16 AC 55 ms
7,708 KB
testcase_17 AC 20 ms
4,480 KB
testcase_18 AC 28 ms
5,400 KB
testcase_19 AC 23 ms
5,064 KB
testcase_20 AC 29 ms
5,196 KB
testcase_21 AC 22 ms
4,376 KB
testcase_22 AC 30 ms
5,468 KB
testcase_23 AC 53 ms
7,708 KB
testcase_24 AC 52 ms
7,828 KB
testcase_25 AC 51 ms
7,776 KB
testcase_26 AC 55 ms
7,692 KB
testcase_27 AC 12 ms
4,380 KB
testcase_28 AC 12 ms
4,380 KB
testcase_29 AC 12 ms
4,376 KB
testcase_30 AC 11 ms
4,380 KB
testcase_31 AC 27 ms
5,168 KB
testcase_32 AC 51 ms
7,448 KB
testcase_33 AC 36 ms
5,068 KB
testcase_34 AC 35 ms
5,320 KB
testcase_35 AC 13 ms
4,380 KB
testcase_36 AC 28 ms
4,380 KB
testcase_37 AC 39 ms
7,692 KB
testcase_38 AC 36 ms
7,848 KB
testcase_39 AC 18 ms
4,380 KB
testcase_40 AC 19 ms
4,376 KB
testcase_41 AC 44 ms
7,300 KB
testcase_42 AC 44 ms
7,352 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