結果

問題 No.135 とりあえず1次元の問題
ユーザー らっしー(raccy)
提出日時 2015-01-25 23:48:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 794 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 69,164 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-03 03:06:41
合計ジャッジ時間 1,577 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int n;
  std::cin >> n;
  std::vector<int> list(n);
  for (auto &x: list) {
    std::cin >> x;
  }

  std::sort(list.begin(), list.end());
  auto result  = std::unique(list.begin(), list.end());
  // std::for_each(list.begin(), result, [](int x){std::cout << x << " ";});

  int min = 0;
  int pre = -1;
  bool same = false;
  std::for_each(list.begin(), result, [&](int x){
    if (pre != -1) {
      if (min == 0) {
        min = x - pre;
        same = false;
      } else if (x - pre == min) {
        same = true;
      } else if (x - pre < min) {
        min = x - pre;
        same = false;
      }
    }
    pre = x;
  });
  // if (same) {
  //   min = 0;
  // }

  std::cout << min << std::endl;
  return 0;
}
0