結果

問題 No.1884 Sequence
ユーザー SSRSSSRS
提出日時 2022-03-25 21:28:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 201,884 KB
実行使用メモリ 8,168 KB
最終ジャッジ日時 2024-04-22 06:04:25
合計ジャッジ時間 6,437 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 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 137 ms
8,168 KB
testcase_11 AC 136 ms
8,028 KB
testcase_12 AC 24 ms
5,376 KB
testcase_13 AC 26 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 79 ms
6,452 KB
testcase_16 AC 129 ms
8,044 KB
testcase_17 AC 57 ms
5,864 KB
testcase_18 AC 79 ms
6,628 KB
testcase_19 AC 63 ms
6,020 KB
testcase_20 AC 68 ms
6,124 KB
testcase_21 AC 53 ms
5,604 KB
testcase_22 AC 75 ms
6,248 KB
testcase_23 AC 132 ms
7,912 KB
testcase_24 AC 133 ms
8,044 KB
testcase_25 AC 126 ms
8,040 KB
testcase_26 AC 126 ms
8,040 KB
testcase_27 AC 30 ms
5,376 KB
testcase_28 AC 28 ms
5,376 KB
testcase_29 AC 29 ms
5,376 KB
testcase_30 AC 31 ms
5,376 KB
testcase_31 AC 72 ms
5,848 KB
testcase_32 AC 134 ms
7,912 KB
testcase_33 AC 123 ms
8,084 KB
testcase_34 AC 121 ms
8,044 KB
testcase_35 AC 34 ms
5,376 KB
testcase_36 AC 87 ms
6,884 KB
testcase_37 AC 120 ms
8,164 KB
testcase_38 AC 106 ms
8,168 KB
testcase_39 AC 49 ms
5,484 KB
testcase_40 AC 51 ms
5,612 KB
testcase_41 AC 107 ms
7,268 KB
testcase_42 AC 105 ms
7,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> B;
  for (int i = 0; i < N; i++){
    if (A[i] != 0){
      B.push_back(A[i]);
    }
  }
  if (B.size() <= 1){
    cout << "Yes" << endl;
  } else if (B == vector<long long>(B.size(), B[0])){
    cout << "Yes" << endl;
  } else {
    int M = B.size();
    sort(B.begin(), B.end());
    long long g = 0;
    bool ok = true;
    for (int i = 0; i < M - 1; i++){
      g = gcd(g, B[i + 1] - B[i]);
      if (B[i] == B[i + 1]){
        ok = false;
      }
    }
    if (!ok){
      cout << "No" << endl;
    } else {
      long long cnt = (B[M - 1] - B[0]) / g + 1;
      if (cnt <= N){
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}
0