結果

問題 No.135 とりあえず1次元の問題
ユーザー yagi2
提出日時 2017-04-24 19:09:10
言語 Java
(openjdk 23)
結果
AC  
実行時間 649 ms / 5,000 ms
コード長 746 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 76,220 KB
実行使用メモリ 62,408 KB
最終ジャッジ日時 2024-09-13 12:05:15
合計ジャッジ時間 9,379 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(Integer.parseInt(sc.next()));
        }

        int d = Integer.MAX_VALUE;
        Collections.sort(p);
        for(int i = 0; i < N - 1; i++) {
            if (Math.abs(p.get(i) - p.get(i+1)) == 0) continue;
            if (d > Math.abs(p.get(i) - p.get(i+1))) d = Math.abs(p.get(i) - p.get(i+1));
        }
        System.out.println((d == Integer.MAX_VALUE)? "0" : d);
    }
}
0