結果

問題 No.135 とりあえず1次元の問題
ユーザー Pump0129Pump0129
提出日時 2018-03-26 22:55:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 557 ms / 5,000 ms
コード長 1,115 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 75,588 KB
実行使用メモリ 74,524 KB
最終ジャッジ日時 2023-09-07 18:29:23
合計ジャッジ時間 8,444 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 541 ms
74,316 KB
testcase_01 AC 118 ms
55,392 KB
testcase_02 AC 119 ms
55,392 KB
testcase_03 AC 121 ms
55,664 KB
testcase_04 AC 124 ms
55,648 KB
testcase_05 AC 121 ms
56,272 KB
testcase_06 AC 121 ms
55,476 KB
testcase_07 AC 122 ms
56,064 KB
testcase_08 AC 122 ms
55,624 KB
testcase_09 AC 122 ms
55,672 KB
testcase_10 AC 123 ms
55,736 KB
testcase_11 AC 120 ms
55,408 KB
testcase_12 AC 138 ms
55,808 KB
testcase_13 AC 124 ms
55,660 KB
testcase_14 AC 169 ms
55,984 KB
testcase_15 AC 136 ms
55,676 KB
testcase_16 AC 155 ms
55,840 KB
testcase_17 AC 164 ms
56,108 KB
testcase_18 AC 121 ms
55,424 KB
testcase_19 AC 161 ms
55,412 KB
testcase_20 AC 136 ms
55,728 KB
testcase_21 AC 455 ms
69,328 KB
testcase_22 AC 557 ms
74,524 KB
evil01.txt AC 523 ms
74,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.no135;

import java.util.*;

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

        int cnt = Integer.parseInt(scan.nextLine());
        List<Integer> pos_list = new ArrayList<>();

        String[] lines = scan.nextLine().split(" ");

        for (int i = 0; i < cnt; i++) {
            pos_list.add(Integer.parseInt(lines[i]));
        }

        scan.close();

        pos_list = new ArrayList<>(new HashSet<>(pos_list));
        Collections.sort(pos_list);

        int min_num = -1;

        if (pos_list.size() != 1) {
            for (int i = 0; i < pos_list.size() - 1; i++) {
                if (min_num == -1){
                    min_num = pos_list.get(i + 1) - pos_list.get(i);
                }else if(pos_list.get(i + 1) - pos_list.get(i) < min_num) {
                    min_num = pos_list.get(i + 1) - pos_list.get(i);
                }
            }
            System.out.println(min_num);
        } else {
            System.out.println(0);
        }
    }
}
0