結果

問題 No.135 とりあえず1次元の問題
ユーザー matsuyoshi30matsuyoshi30
提出日時 2017-02-21 22:36:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 589 ms / 5,000 ms
コード長 912 bytes
コンパイル時間 2,516 ms
コンパイル使用メモリ 73,344 KB
実行使用メモリ 61,096 KB
最終ジャッジ日時 2023-09-07 22:51:19
合計ジャッジ時間 9,373 ms
ジャッジサーバーID
(参考情報)
judge5 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 583 ms
60,880 KB
testcase_01 AC 123 ms
56,104 KB
testcase_02 AC 127 ms
56,180 KB
testcase_03 AC 123 ms
55,816 KB
testcase_04 AC 134 ms
53,904 KB
testcase_05 AC 133 ms
55,948 KB
testcase_06 AC 134 ms
56,048 KB
testcase_07 AC 136 ms
56,132 KB
testcase_08 AC 138 ms
56,160 KB
testcase_09 AC 136 ms
56,056 KB
testcase_10 AC 136 ms
55,976 KB
testcase_11 AC 136 ms
55,928 KB
testcase_12 AC 155 ms
55,800 KB
testcase_13 AC 137 ms
55,768 KB
testcase_14 AC 192 ms
56,244 KB
testcase_15 AC 158 ms
56,032 KB
testcase_16 AC 191 ms
56,376 KB
testcase_17 AC 192 ms
56,040 KB
testcase_18 AC 144 ms
55,884 KB
testcase_19 AC 195 ms
56,628 KB
testcase_20 AC 185 ms
56,196 KB
testcase_21 AC 551 ms
60,984 KB
testcase_22 AC 589 ms
61,096 KB
evil01.txt AC 587 ms
61,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] x = new int[n];
        for(int i=0; i<n; i++) {
            x[i] = in.nextInt();
        }
        Arrays.sort(x);

        if(n == 1) {
            System.out.println(0);
        } else {
            int len = Integer.MAX_VALUE;
            for(int i=1; i<n; i++) {
                if(x[i] != x[i-1]) {
                    len = Math.min(len, Math.abs(x[i] - x[i-1]));
                } else {
                    continue;
                }
            }

            if(len == Integer.MAX_VALUE) {
                System.out.println(0);
            } else {
                System.out.println(len);
            }
        }

        in.close();
    }
}
0