結果

問題 No.135 とりあえず1次元の問題
ユーザー matsuyoshi30matsuyoshi30
提出日時 2017-02-21 22:24:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 584 ms / 5,000 ms
コード長 858 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 73,172 KB
実行使用メモリ 61,080 KB
最終ジャッジ日時 2023-09-02 00:51:22
合計ジャッジ時間 8,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 543 ms
60,428 KB
testcase_01 AC 120 ms
56,156 KB
testcase_02 AC 120 ms
55,992 KB
testcase_03 AC 118 ms
55,864 KB
testcase_04 AC 130 ms
55,864 KB
testcase_05 AC 132 ms
56,064 KB
testcase_06 AC 130 ms
55,984 KB
testcase_07 AC 131 ms
56,064 KB
testcase_08 AC 131 ms
56,416 KB
testcase_09 AC 131 ms
56,420 KB
testcase_10 AC 131 ms
56,368 KB
testcase_11 AC 134 ms
56,316 KB
testcase_12 AC 151 ms
55,880 KB
testcase_13 AC 131 ms
55,920 KB
testcase_14 AC 179 ms
56,200 KB
testcase_15 AC 146 ms
56,092 KB
testcase_16 AC 178 ms
56,080 KB
testcase_17 AC 184 ms
56,028 KB
testcase_18 AC 137 ms
55,568 KB
testcase_19 AC 177 ms
56,780 KB
testcase_20 AC 175 ms
54,396 KB
testcase_21 AC 535 ms
60,600 KB
testcase_22 AC 584 ms
61,080 KB
evil01.txt AC 550 ms
60,736 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]));
                }
            }

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

        in.close();
    }
}
0