結果

問題 No.135 とりあえず1次元の問題
ユーザー snrnsidy
提出日時 2021-05-30 19:57:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 629 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 198,744 KB
最終ジャッジ日時 2025-01-21 20:47:39
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, t;
    vector <int> v;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> t;
        v.push_back(t);
    }

    sort(v.begin(), v.end());

    int res = 1e9;

    for (int i = 1; i < n - 1; i++)
    {
        if (v[i - 1] != v[i])
        {
            res = min(res, abs(v[i] - v[i - 1]));
        }
        if (v[i + 1] != v[i])
        {
            res = min(res, abs(v[i] - v[i + 1]));
        }
    }
    
    if(res>=1e9) res = 0;

    cout << res << '\n';

    return 0;
}
0