結果

問題 No.135 とりあえず1次元の問題
ユーザー weaken
提出日時 2020-10-08 07:23:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 197,812 KB
最終ジャッジ日時 2025-01-15 03:26:51
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define MAX 1000000
using namespace std;

int main() {
  fastIO;
  int n;
  cin >> n;

  if (n <= 1) {
    cout << 0 << '\n';
    return 0;
  }

  vector<int> ps(n);
  for (auto &p : ps)
    cin >> p;
  sort(ps.begin(), ps.end());

  int minv = MAX + 1;
  for (size_t i = 0; i < ps.size() - 1; ++i) {
    int cur = ps[i], next = ps[i + 1];
    if (cur != next)
      minv = min(abs(cur - next), minv);
  }

  // all points are same ?
  if (minv == MAX + 1)
    cout << 0 << '\n';
  else
    cout << minv << '\n';

  return 0;
}
0