結果

問題 No.135 とりあえず1次元の問題
ユーザー ut0s
提出日時 2019-09-06 08:12:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 735 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 174,064 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-23 12:58:40
合計ジャッジ時間 2,666 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
  @file 135.cpp
  @title  No.135 とりあえず1次元の問題 - yukicoder
  @url https://yukicoder.me/problems/no/135
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

int main() {
  LL N;
  cin >> N;
  vector<LL> X(N, 0);
  REP(i, N) {
    cin >> X[i];
  }

  LL ans = -1;
  if (N != 1) {
    sort(ALL(X));

    vector<LL> diff(N - 1);
    for (int i = 1; i < N; i++) {
      diff[i - 1] = X[i] - X[i - 1];
    }
    sort(ALL(diff));
    diff.erase(unique(ALL(diff)), diff.end());
    if (diff[0] != 0) {
      ans = diff[0];
    } else {
      ans = diff[1];
    }
  }

  cout << ans << endl;
  return 0;
  }
0