結果

問題 No.406 鴨等間隔の法則
ユーザー nali
提出日時 2019-07-28 15:59:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 451 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 75,764 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-07 12:40:20
合計ジャッジ時間 2,454 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n, d;
  cin >> n;
  vector<int> x(n);
  for (auto& e : x) cin >> e;
  sort(x.begin(), x.end());
  d = x[1] - x[0];
  bool f = (d != 0);
  if (!f) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 1; i < n - 1; i++) {
    if (x[i + 1] - x[i] != d) {
      f = false;
      break;
    }
  }
  cout << (f ? "YES" : "NO") << endl;
  return 0;
}
0