結果

問題 No.1884 Sequence
ユーザー MatsuTakuMatsuTaku
提出日時 2022-03-25 21:41:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,860 bytes
コンパイル時間 3,165 ms
コンパイル使用メモリ 307,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 06:23:08
合計ジャッジ時間 5,806 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 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 69 ms
5,376 KB
testcase_11 AC 64 ms
5,376 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 14 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 38 ms
5,376 KB
testcase_16 AC 56 ms
5,376 KB
testcase_17 AC 23 ms
5,376 KB
testcase_18 AC 29 ms
5,376 KB
testcase_19 AC 26 ms
5,376 KB
testcase_20 AC 32 ms
5,376 KB
testcase_21 AC 28 ms
5,376 KB
testcase_22 AC 37 ms
5,376 KB
testcase_23 AC 55 ms
5,376 KB
testcase_24 AC 54 ms
5,376 KB
testcase_25 AC 52 ms
5,376 KB
testcase_26 AC 53 ms
5,376 KB
testcase_27 AC 16 ms
5,376 KB
testcase_28 AC 15 ms
5,376 KB
testcase_29 AC 15 ms
5,376 KB
testcase_30 AC 16 ms
5,376 KB
testcase_31 AC 28 ms
5,376 KB
testcase_32 AC 48 ms
5,376 KB
testcase_33 AC 39 ms
5,376 KB
testcase_34 AC 40 ms
5,376 KB
testcase_35 AC 18 ms
5,376 KB
testcase_36 AC 32 ms
5,376 KB
testcase_37 AC 39 ms
5,376 KB
testcase_38 AC 35 ms
5,376 KB
testcase_39 AC 21 ms
5,376 KB
testcase_40 AC 24 ms
5,376 KB
testcase_41 AC 45 ms
5,376 KB
testcase_42 AC 45 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
  Author : MatsuTaku
  Date   : 03/25/22
*/

#include <bits/stdc++.h>
#include <x86intrin.h>
//#include <atcoder/all>
#define _overload3(_1, _2, _3, target, ...) target
#define _REP(i, l, r)   for (int i = (l), i##_less = (r); i < i##_less; i++)
#define _rep(i, n)      _REP(i, 0, n)
#define rep(args...)    _overload3(args, _REP, _rep)(args)
#define _RREP(i, l, r)  for (int i = (r)-1, i##_least = (l); i >= i##_least; i--)
#define _rrep(i, n)     _RREP(i, 0, n)
#define rrep(args...)   _overload3(args, _RREP, _rrep)(args)
#define chmax(dst, x)   dst = max(dst, (x))
#define chmin(dst, x)   dst = min(dst, (x))
using namespace std;
using lint = long long int;
using ulint = unsigned long long int;
template<typename T>
using vvec = vector<vector<T>>;
template<typename T>
vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); }
template<typename T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;

class Solver {
 public:
  Solver();
  void solve();
};

Solver::Solver() {}

void Solver::solve() {
  int n;
  cin >> n;
  vector<lint> A(n);
  rep(i, n) cin >> A[i];
  sort(A.begin(), A.end());
  int k = 0;
  while (k < n and A[k] == 0)
    k++;
  bool ans;
  if (k == n) {
    ans = true;
  } else {
    lint mind = 1e18;
    rep(i, k, n-1) chmin(mind, A[i+1]-A[i]);
    if (mind == 0) {
      ans = A[n - 1] == A[k];
    } else {
      rrep(i, k, n) A[i] -= A[k];
      lint g = A[k + 1];
      rep(i, k + 1, n) {
        g = gcd(g, A[i]);
      }
      lint c = 0;
      rep(i, k, n - 1) {
        lint d = A[i + 1] - A[i];
        c += d / g - 1;
      }
      ans = c <= k;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  Solver solver;
  int t = 1;
//  cin>>t;
  while (t--) {
    solver.solve();
  }
  return 0;
}
0