結果

問題 No.135 とりあえず1次元の問題
ユーザー r.suzukir.suzuki
提出日時 2016-01-02 21:53:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 753 ms / 5,000 ms
コード長 851 bytes
コンパイル時間 4,708 ms
コンパイル使用メモリ 79,312 KB
実行使用メモリ 81,532 KB
最終ジャッジ日時 2023-09-01 23:07:56
合計ジャッジ時間 12,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 736 ms
77,780 KB
testcase_01 AC 126 ms
55,772 KB
testcase_02 AC 126 ms
55,548 KB
testcase_03 AC 125 ms
55,664 KB
testcase_04 AC 137 ms
55,428 KB
testcase_05 AC 137 ms
55,744 KB
testcase_06 AC 137 ms
55,816 KB
testcase_07 AC 136 ms
55,808 KB
testcase_08 AC 137 ms
55,876 KB
testcase_09 AC 137 ms
55,468 KB
testcase_10 AC 138 ms
55,740 KB
testcase_11 AC 138 ms
55,920 KB
testcase_12 AC 157 ms
55,604 KB
testcase_13 AC 138 ms
55,524 KB
testcase_14 AC 192 ms
55,936 KB
testcase_15 AC 159 ms
55,788 KB
testcase_16 AC 197 ms
56,372 KB
testcase_17 AC 195 ms
55,968 KB
testcase_18 AC 146 ms
55,684 KB
testcase_19 AC 194 ms
55,812 KB
testcase_20 AC 180 ms
57,772 KB
testcase_21 AC 601 ms
75,048 KB
testcase_22 AC 753 ms
81,532 KB
evil01.txt AC 668 ms
76,832 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);
		if(ans == Integer.MAX_VALUE){
			ans = 0;
		}
		System.out.println(ans);
		sc.close();

	}

}
0