結果

問題 No.135 とりあえず1次元の問題
ユーザー koukonkokoukonko
提出日時 2015-12-12 15:39:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 727 ms / 5,000 ms
コード長 713 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 72,856 KB
実行使用メモリ 66,992 KB
最終ジャッジ日時 2023-09-01 22:58:02
合計ジャッジ時間 9,836 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 696 ms
66,992 KB
testcase_01 AC 128 ms
55,768 KB
testcase_02 AC 126 ms
55,688 KB
testcase_03 AC 124 ms
55,736 KB
testcase_04 AC 138 ms
55,872 KB
testcase_05 AC 137 ms
55,748 KB
testcase_06 AC 138 ms
57,628 KB
testcase_07 AC 136 ms
55,676 KB
testcase_08 AC 139 ms
55,788 KB
testcase_09 AC 138 ms
56,036 KB
testcase_10 AC 138 ms
56,388 KB
testcase_11 AC 138 ms
55,884 KB
testcase_12 AC 156 ms
55,528 KB
testcase_13 AC 137 ms
55,944 KB
testcase_14 AC 187 ms
56,128 KB
testcase_15 AC 161 ms
56,056 KB
testcase_16 AC 189 ms
56,176 KB
testcase_17 AC 192 ms
56,708 KB
testcase_18 AC 141 ms
55,772 KB
testcase_19 AC 191 ms
55,956 KB
testcase_20 AC 185 ms
56,000 KB
testcase_21 AC 587 ms
62,984 KB
testcase_22 AC 727 ms
66,848 KB
evil01.txt AC 667 ms
63,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		try {
			Scanner scan = new Scanner(System.in);
			int N = scan.nextInt();
			ArrayList<Integer> x = new ArrayList<>(N);
			int ans = Integer.MAX_VALUE;

			for (int i = 0; i < N; ++i) {
				x.add(scan.nextInt());
			}
			x.sort(null);

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

				if (!x.get(i).equals(x.get(i + 1))) {
					if (Math.abs(x.get(i) - x.get(i + 1)) < ans) {
						ans = Math.abs(x.get(i) - x.get(i + 1));
					}
				}
			}

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

			scan.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
0