結果
| 問題 | No.1884 Sequence | 
| コンテスト | |
| ユーザー |  houren | 
| 提出日時 | 2022-03-25 21:34:17 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 56 ms / 2,000 ms | 
| コード長 | 964 bytes | 
| コンパイル時間 | 1,737 ms | 
| コンパイル使用メモリ | 174,236 KB | 
| 実行使用メモリ | 7,904 KB | 
| 最終ジャッジ日時 | 2024-10-14 05:27:49 | 
| 合計ジャッジ時間 | 4,391 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 40 | 
ソースコード
#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;
}
            
            
            
        