結果

問題 No.1884 Sequence
ユーザー tnakao0123tnakao0123
提出日時 2022-03-28 22:59:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 48,220 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-04-25 03:38:03
合計ジャッジ時間 3,621 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
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 55 ms
6,912 KB
testcase_11 AC 55 ms
6,784 KB
testcase_12 AC 19 ms
5,376 KB
testcase_13 AC 20 ms
5,376 KB
testcase_14 AC 19 ms
5,376 KB
testcase_15 AC 41 ms
6,016 KB
testcase_16 AC 57 ms
6,912 KB
testcase_17 AC 32 ms
5,760 KB
testcase_18 AC 42 ms
6,144 KB
testcase_19 AC 29 ms
5,760 KB
testcase_20 AC 37 ms
6,016 KB
testcase_21 AC 31 ms
5,504 KB
testcase_22 AC 38 ms
5,888 KB
testcase_23 AC 56 ms
6,912 KB
testcase_24 AC 56 ms
6,912 KB
testcase_25 AC 53 ms
6,784 KB
testcase_26 AC 54 ms
6,912 KB
testcase_27 AC 23 ms
5,376 KB
testcase_28 AC 22 ms
5,376 KB
testcase_29 AC 22 ms
5,376 KB
testcase_30 AC 22 ms
5,376 KB
testcase_31 AC 33 ms
5,376 KB
testcase_32 AC 53 ms
6,656 KB
testcase_33 AC 39 ms
5,376 KB
testcase_34 AC 39 ms
5,376 KB
testcase_35 AC 24 ms
5,376 KB
testcase_36 AC 35 ms
5,376 KB
testcase_37 AC 39 ms
5,376 KB
testcase_38 AC 36 ms
5,376 KB
testcase_39 AC 27 ms
5,376 KB
testcase_40 AC 28 ms
5,376 KB
testcase_41 AC 48 ms
6,400 KB
testcase_42 AC 49 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1884.cc:  No.1884 Sequence - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

ll as[MAX_N], ds[MAX_N];

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m >= 0, n >= 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%lld", as + i);
    if (as[i] == 0) as[i] = LINF;
  }
  sort(as, as + n);

  int m = 0, c = 0;
  for (ll pa = 0; m < n && as[m] < LINF; m++)
    if (pa != as[m]) pa = as[m], c++;
  //printf("m=%d\n", m);

  if (m <= 2 || c == 1) { puts("Yes"); return 0; }

  ll g = 0;
  for (int i = 0; i + 1 < m; i++) {
    ds[i] = as[i + 1] - as[i];
    if (ds[i] == 0) { puts("No"); return 0; }
    g = gcd(g, ds[i]);
  }
  //printf("g=%lld\n", g);

  int r = n - m;
  for (int i = 0; i + 1 < m; i++) {
    ll q = ds[i] / g - 1;
    if (q > r) { puts("No"); return 0; }
    r -= q;
  }

  puts("Yes");
  return 0;
}
0