結果

問題 No.135 とりあえず1次元の問題
ユーザー nCk_cvnCk_cv
提出日時 2016-01-21 02:15:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 615 ms / 5,000 ms
コード長 728 bytes
コンパイル時間 4,792 ms
コンパイル使用メモリ 73,832 KB
実行使用メモリ 60,860 KB
最終ジャッジ日時 2023-09-01 23:18:58
合計ジャッジ時間 9,322 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 611 ms
60,808 KB
testcase_01 AC 128 ms
55,536 KB
testcase_02 AC 126 ms
55,964 KB
testcase_03 AC 128 ms
55,748 KB
testcase_04 AC 138 ms
55,676 KB
testcase_05 AC 137 ms
55,704 KB
testcase_06 AC 137 ms
55,232 KB
testcase_07 AC 137 ms
55,708 KB
testcase_08 AC 137 ms
55,760 KB
testcase_09 AC 139 ms
55,320 KB
testcase_10 AC 137 ms
55,892 KB
testcase_11 AC 136 ms
55,592 KB
testcase_12 AC 161 ms
58,020 KB
testcase_13 AC 137 ms
55,664 KB
testcase_14 AC 191 ms
55,692 KB
testcase_15 AC 158 ms
55,700 KB
testcase_16 AC 192 ms
56,780 KB
testcase_17 AC 189 ms
55,820 KB
testcase_18 AC 144 ms
53,488 KB
testcase_19 AC 190 ms
55,948 KB
testcase_20 AC 184 ms
55,952 KB
testcase_21 AC 574 ms
60,860 KB
testcase_22 AC 615 ms
60,692 KB
evil01.txt AC 595 ms
63,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] x = new int[N];
		for(int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			int idx1 = (int)(Math.random() * N);
			int idx2 = (int)(Math.random() * N);
			int tmp = x[idx1];
			x[idx1] = x[idx2];
			x[idx2] = tmp;
		}
		if(N == 1) System.out.println("0");
		int MIN = Integer.MAX_VALUE;
		
		Arrays.sort(x);
		for(int i = 0; i < N-1; i++) {
			if(x[i] == x[i+1]) continue;
			MIN = Math.min(MIN, (int)Math.abs(x[i] - x[i+1]));
		}
		if(MIN == Integer.MAX_VALUE) MIN = 0;
		System.out.println(MIN);
	}
}
0