結果

問題 No.1884 Sequence
ユーザー gucci0512gucci0512
提出日時 2022-03-25 22:14:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,675 bytes
コンパイル時間 3,877 ms
コンパイル使用メモリ 234,900 KB
実行使用メモリ 17,792 KB
最終ジャッジ日時 2024-04-22 06:53:53
合計ジャッジ時間 15,295 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 199 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 263 ms
17,664 KB
testcase_11 AC 264 ms
17,664 KB
testcase_12 AC 248 ms
5,376 KB
testcase_13 AC 162 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 275 ms
17,536 KB
testcase_17 AC 113 ms
8,832 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 275 ms
17,664 KB
testcase_24 AC 311 ms
17,536 KB
testcase_25 WA -
testcase_26 AC 261 ms
17,664 KB
testcase_27 AC 33 ms
5,376 KB
testcase_28 AC 32 ms
5,376 KB
testcase_29 AC 167 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 102 ms
9,984 KB
testcase_32 AC 230 ms
16,896 KB
testcase_33 AC 112 ms
5,376 KB
testcase_34 AC 111 ms
5,376 KB
testcase_35 AC 34 ms
5,376 KB
testcase_36 AC 83 ms
5,376 KB
testcase_37 AC 111 ms
5,376 KB
testcase_38 AC 99 ms
5,376 KB
testcase_39 AC 46 ms
5,376 KB
testcase_40 AC 50 ms
5,376 KB
testcase_41 TLE -
testcase_42 TLE -
権限があれば一括ダウンロードができます

ソースコード

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;
    }
    set<ll> t;
    for(ll i=1;i*i<=d;i++){
        if(d%i==0){
            t.insert(i);
            t.insert(d/i);
        }
    }
    string ans="No";
    for(ll j:t){
        ll ex=-1;
        bool f=true;
        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){
            ll sum2=sum;
            sum2-=(cnt*j);
            sum2/=j;

            if(sum2<=zero){
                ans="Yes";
            }
        }
    }
    cout << ans << endl;
}
0