結果

問題 No.1884 Sequence
ユーザー gucci0512gucci0512
提出日時 2022-03-25 21:58:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,346 bytes
コンパイル時間 4,122 ms
コンパイル使用メモリ 232,692 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-04-22 06:39:37
合計ジャッジ時間 11,287 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 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 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 367 ms
17,664 KB
testcase_11 AC 381 ms
17,536 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 33 ms
5,376 KB
testcase_15 AC 182 ms
11,264 KB
testcase_16 AC 372 ms
17,536 KB
testcase_17 WA -
testcase_18 AC 170 ms
12,160 KB
testcase_19 AC 123 ms
10,112 KB
testcase_20 AC 137 ms
9,856 KB
testcase_21 AC 94 ms
8,192 KB
testcase_22 AC 156 ms
10,752 KB
testcase_23 AC 380 ms
17,664 KB
testcase_24 AC 380 ms
17,664 KB
testcase_25 AC 369 ms
17,664 KB
testcase_26 AC 367 ms
17,664 KB
testcase_27 AC 35 ms
5,376 KB
testcase_28 AC 35 ms
5,376 KB
testcase_29 AC 35 ms
5,376 KB
testcase_30 AC 36 ms
5,376 KB
testcase_31 AC 130 ms
10,112 KB
testcase_32 AC 331 ms
17,024 KB
testcase_33 AC 123 ms
5,376 KB
testcase_34 AC 124 ms
5,376 KB
testcase_35 AC 39 ms
5,376 KB
testcase_36 AC 92 ms
5,376 KB
testcase_37 AC 123 ms
5,376 KB
testcase_38 AC 110 ms
5,376 KB
testcase_39 AC 52 ms
5,376 KB
testcase_40 AC 55 ms
5,376 KB
testcase_41 AC 277 ms
14,592 KB
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b) for(int i=b-1;i>=0;i--)
#define rbit(i,a) for(int i=0;i<(1<<a);i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double lld;
using namespace std;
using namespace atcoder;
using mint=static_modint<1000000007>;
const ll mod=998244353;
//const ll mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const string zton="0123456789";
const string atoz="abcdefghijklmnopqrstuvwxyz";
ll gcd(ll a,ll b){
    ll r;
    r=a%b;
    if(r==0){
        return b;
    }
    else{
        return gcd(b,r);
    }
}
typedef pair<ll,int> P;

int main(void){
    int N;cin >> N;
    ll A[N];
    int zero=0;
    map<ll,int> s;
    rep(i,0,N){
        cin >> A[i];
        if(A[i]==0)zero++;
        s[A[i]]=s[A[i]]+1;
    }
    for(auto p:s){
        if(p.second>=2){
            if(p.first==0)continue;
            if(s.size()==1){
                cout << "Yes" << endl;
                return 0;
            }
            if(s.size()==2){
                if(s.count(0)){
                    cout << "Yes" << endl;
                }
                else{
                    cout << "No" << endl;
                }
                return 0;
            }
            cout << "No" << endl;
            return 0;
        }
    }
    sort(A,A+N);
    ll d=-1;
    ll sum=0;
    ll cnt=0;
    rep(i,0,N-1){
        if(A[i]!=0&&A[i]!=A[i+1]){
            if(d==-1){
                d=A[i+1]-A[i];
                sum+=(A[i+1]-A[i]);
                cnt++;
            }
            else{
                ll d=gcd(d,A[i+1]-A[i]);
                sum+=(A[i+1]-A[i]);
                cnt++;
            }
        }
    }
    if(d==-1){
        cout << "Yes" << endl;
        return 0;
    }
    sum-=(cnt*d);
    sum/=d;
    if(sum>zero){
        cout << "No" << endl;
        return 0;
    }
    ll ex=-1;
    rep(i,0,N){
        if(A[i]==0)continue;
        if(A[i]!=0){
            if(ex==-1)ex=(A[i]%d);
            if(ex!=A[i]%d){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}
0