結果

問題 No.1884 Sequence
ユーザー akasinn
提出日時 2022-03-26 12:54:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 173,284 KB
実行使用メモリ 5,584 KB
最終ジャッジ日時 2024-10-15 04:51:43
合計ジャッジ時間 5,940 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

/*yukicoder No.1884 Sequence*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

//ユークリッドの互除法(0<x<y)
ll gojyohou(ll x,ll y){
  ll a=y%x;
  if(a){//a!=0
    return gojyohou(a,x);
  }else{//a==0
    return x;
  }
}

int main(){
  int n,zero=0;
  vector<ll> A(0);
  cin>>n;
  while(n--){
    ll i;
    cin>>i;
    if(i){//i!=0
      A.push_back(i);
    }else{//i==0
      zero++;
    }
  }
  n=A.size();
  if(n<3){
    printf("Yes\n");
    return 0;
  }
  sort(A.begin(),A.end());//小さい順に
  for(int i=1;i<n;i++){
    if(A.at(i-1)==A.at(i)){
      if(A.at(0)==A.at(n-1))cout<<"Yes\n";
      else cout<<"No\n";
      return 0;
    }
  }
  for(int i=1;i<n;i++){
    A.at(i)-=A.at(0);
  }
  ll gcd=gojyohou(A.at(1),A.at(2));
  for(int i=3;i<n;i++){
    gcd=gojyohou(gcd,A.at(i));
  }
  ll needs=A.at(n-1)/gcd+1-n;
  if(needs<=zero)cout<<"Yes\n";else cout<<"No\n";
  //cout<<gcd;
  return 0;
}
0