結果

問題 No.1884 Sequence
ユーザー gucci0512gucci0512
提出日時 2022-03-25 22:56:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 2,660 bytes
コンパイル時間 4,868 ms
コンパイル使用メモリ 235,008 KB
実行使用メモリ 17,792 KB
最終ジャッジ日時 2024-04-22 07:46:15
合計ジャッジ時間 13,437 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 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 207 ms
5,376 KB
testcase_08 AC 210 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 379 ms
17,536 KB
testcase_11 AC 371 ms
17,792 KB
testcase_12 AC 257 ms
5,376 KB
testcase_13 AC 170 ms
5,376 KB
testcase_14 AC 34 ms
5,376 KB
testcase_15 AC 186 ms
11,392 KB
testcase_16 AC 379 ms
17,536 KB
testcase_17 AC 94 ms
8,704 KB
testcase_18 AC 171 ms
12,416 KB
testcase_19 AC 125 ms
10,240 KB
testcase_20 AC 141 ms
9,856 KB
testcase_21 AC 96 ms
8,192 KB
testcase_22 AC 164 ms
10,496 KB
testcase_23 AC 388 ms
17,664 KB
testcase_24 AC 378 ms
17,792 KB
testcase_25 AC 368 ms
17,664 KB
testcase_26 AC 375 ms
17,792 KB
testcase_27 AC 36 ms
5,376 KB
testcase_28 AC 36 ms
5,376 KB
testcase_29 AC 169 ms
5,376 KB
testcase_30 AC 187 ms
5,376 KB
testcase_31 AC 131 ms
10,240 KB
testcase_32 AC 344 ms
17,152 KB
testcase_33 AC 124 ms
5,376 KB
testcase_34 AC 124 ms
5,376 KB
testcase_35 AC 39 ms
5,376 KB
testcase_36 AC 93 ms
5,376 KB
testcase_37 AC 125 ms
5,376 KB
testcase_38 AC 111 ms
5,376 KB
testcase_39 AC 52 ms
5,376 KB
testcase_40 AC 56 ms
5,376 KB
testcase_41 AC 278 ms
14,592 KB
testcase_42 AC 275 ms
14,720 KB
権限があれば一括ダウンロードができます

ソースコード

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;
    }
    vector<ll> que;
    for(ll i=1;i*i<=d;i++){
        if(d%i==0){
            que.push_back(i);
            que.push_back(d/i);
        }
    }
    sort(all(que));
    for(ll j:que){
        bool f=true;
        if(f){
            ll sum2=sum;
            sum2-=(cnt*j);
            sum2/=j;
            if(sum2>zero){
                continue;
            }
        }
        ll ex=-1;
        rep(i,0,N){
            if(A[i]==0)continue;
            if(ex==-1)ex=A[i]%j;
            if(ex!=A[i]%j){
                f=false;
                break;
            }
        }
        if(!f)continue;
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}
0