結果

問題 No.135 とりあえず1次元の問題
ユーザー r.suzukir.suzuki
提出日時 2016-01-02 21:43:45
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 803 bytes
コンパイル時間 5,064 ms
コンパイル使用メモリ 75,272 KB
実行使用メモリ 81,636 KB
最終ジャッジ日時 2023-09-01 23:03:10
合計ジャッジ時間 11,911 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 790 ms
80,724 KB
testcase_01 AC 128 ms
55,712 KB
testcase_02 AC 130 ms
55,512 KB
testcase_03 WA -
testcase_04 AC 136 ms
55,532 KB
testcase_05 AC 139 ms
55,808 KB
testcase_06 AC 140 ms
55,824 KB
testcase_07 AC 140 ms
55,520 KB
testcase_08 AC 138 ms
56,000 KB
testcase_09 AC 138 ms
55,832 KB
testcase_10 AC 136 ms
55,708 KB
testcase_11 AC 139 ms
55,784 KB
testcase_12 AC 161 ms
55,752 KB
testcase_13 AC 138 ms
55,860 KB
testcase_14 AC 193 ms
56,428 KB
testcase_15 AC 161 ms
56,036 KB
testcase_16 AC 197 ms
54,372 KB
testcase_17 AC 201 ms
56,568 KB
testcase_18 AC 148 ms
55,780 KB
testcase_19 AC 193 ms
56,384 KB
testcase_20 AC 186 ms
56,240 KB
testcase_21 AC 601 ms
76,376 KB
testcase_22 AC 759 ms
81,636 KB
evil01.txt AC 662 ms
81,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No_166 {
	static int shortestDistance(ArrayList list, int i1, int i2, int m) {
		int num1 = (int) list.get(i1);
		int num2 = (int) list.get(i2);
		int min = m;
		if (num1 != num2) {
			min = Math.min(m, Math.abs(num1 - num2));
		}
		if (i2 >= list.size() - 1) {
			return min;
		} else {
			return shortestDistance(list, ++i1, ++i2, min);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int n = sc.nextInt();

		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}

		Collections.sort(list);
		int ans = shortestDistance(list, 0, 1, Integer.MAX_VALUE);
		System.out.println(ans);
		sc.close();

	}

}
0