結果

問題 No.135 とりあえず1次元の問題
ユーザー abcabc
提出日時 2016-11-08 02:49:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 591 ms / 5,000 ms
コード長 763 bytes
コンパイル時間 3,551 ms
コンパイル使用メモリ 71,672 KB
実行使用メモリ 60,472 KB
最終ジャッジ日時 2023-09-02 00:39:10
合計ジャッジ時間 9,194 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 591 ms
60,288 KB
testcase_01 AC 125 ms
55,628 KB
testcase_02 AC 124 ms
55,780 KB
testcase_03 AC 124 ms
55,712 KB
testcase_04 AC 136 ms
55,744 KB
testcase_05 AC 137 ms
55,808 KB
testcase_06 AC 137 ms
55,812 KB
testcase_07 AC 137 ms
55,688 KB
testcase_08 AC 137 ms
55,624 KB
testcase_09 AC 136 ms
55,532 KB
testcase_10 AC 137 ms
55,888 KB
testcase_11 AC 139 ms
55,780 KB
testcase_12 AC 157 ms
55,548 KB
testcase_13 AC 139 ms
55,812 KB
testcase_14 AC 182 ms
55,848 KB
testcase_15 AC 157 ms
55,980 KB
testcase_16 AC 180 ms
55,944 KB
testcase_17 AC 186 ms
55,768 KB
testcase_18 AC 143 ms
55,644 KB
testcase_19 AC 183 ms
56,140 KB
testcase_20 AC 179 ms
55,972 KB
testcase_21 AC 534 ms
60,428 KB
testcase_22 AC 584 ms
60,472 KB
evil01.txt AC 587 ms
62,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        if (n == 0) {
            System.out.println(0);
            return;
        }

        int[] x = new int[n];

        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }

        Arrays.sort(x);

        if (x[0] == x[n-1]) {
            System.out.println(0);
            return;
        }
        int min = Integer.MAX_VALUE;

        for (int i = 0; i < n - 1; i++) {

            if (0 < (x[i + 1] - x[i])) {

                min = Math.min(min, x[i + 1] - x[i]);

            }

        }

        System.out.println(min);

    }

}
0