結果

問題 No.135 とりあえず1次元の問題
ユーザー startcpp
提出日時 2015-02-06 22:24:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 599 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 63,836 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2025-01-03 05:15:38
合計ジャッジ時間 1,794 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

//最小の点…点iに注目すると、隣の点以外調べなくて良い。
//自分と同じ座標のものを除いておくとよい→set使えば!?
#include<iostream>
#include<set>
using namespace std;

int N;
int X;

int main() {
int i;
cin >> N;
static set<int> P;
set<int>::iterator it, prev_it;
for( i = 0; i < N; i++ ) {
cin >> X;
P.insert(X);
}

int ans = 114514810;
for(set<int>::iterator it = P.begin(); it != P.end(); it++) {
if (it != P.begin())
ans = min(ans, *it - *prev_it);
prev_it = it;
}

if ( ans < 114514810 )
cout << ans << endl;
else
cout << 0 << endl;
return 0;
}
0