結果

問題 No.135 とりあえず1次元の問題
ユーザー yagi2yagi2
提出日時 2017-04-24 19:09:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 595 ms / 5,000 ms
コード長 746 bytes
コンパイル時間 3,024 ms
コンパイル使用メモリ 74,316 KB
実行使用メモリ 65,484 KB
最終ジャッジ日時 2023-10-11 13:20:07
合計ジャッジ時間 9,248 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 595 ms
63,808 KB
testcase_01 AC 118 ms
55,416 KB
testcase_02 AC 119 ms
55,844 KB
testcase_03 AC 119 ms
55,468 KB
testcase_04 AC 128 ms
55,828 KB
testcase_05 AC 128 ms
56,148 KB
testcase_06 AC 127 ms
56,184 KB
testcase_07 AC 130 ms
56,076 KB
testcase_08 AC 126 ms
55,780 KB
testcase_09 AC 132 ms
56,184 KB
testcase_10 AC 129 ms
55,768 KB
testcase_11 AC 128 ms
56,172 KB
testcase_12 AC 143 ms
55,892 KB
testcase_13 AC 128 ms
56,192 KB
testcase_14 AC 173 ms
56,448 KB
testcase_15 AC 142 ms
56,120 KB
testcase_16 AC 176 ms
56,604 KB
testcase_17 AC 175 ms
56,668 KB
testcase_18 AC 130 ms
56,012 KB
testcase_19 AC 175 ms
56,628 KB
testcase_20 AC 171 ms
56,748 KB
testcase_21 AC 542 ms
64,604 KB
testcase_22 AC 587 ms
65,484 KB
evil01.txt AC 592 ms
65,808 KB
権限があれば一括ダウンロードができます

ソースコード

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