結果

問題 No.130 XOR Minimax
ユーザー 37zigen37zigen
提出日時 2016-11-25 00:19:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,017 ms / 5,000 ms
コード長 985 bytes
コンパイル時間 3,884 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 70,836 KB
最終ジャッジ日時 2023-10-10 00:16:42
合計ジャッジ時間 20,061 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 655 ms
63,012 KB
testcase_01 AC 126 ms
55,628 KB
testcase_02 AC 128 ms
55,432 KB
testcase_03 AC 127 ms
56,104 KB
testcase_04 AC 666 ms
65,408 KB
testcase_05 AC 819 ms
70,836 KB
testcase_06 AC 801 ms
70,048 KB
testcase_07 AC 891 ms
69,468 KB
testcase_08 AC 1,017 ms
67,784 KB
testcase_09 AC 367 ms
60,572 KB
testcase_10 AC 424 ms
60,744 KB
testcase_11 AC 789 ms
69,128 KB
testcase_12 AC 289 ms
60,456 KB
testcase_13 AC 712 ms
65,328 KB
testcase_14 AC 942 ms
65,600 KB
testcase_15 AC 207 ms
58,484 KB
testcase_16 AC 728 ms
65,952 KB
testcase_17 AC 771 ms
65,924 KB
testcase_18 AC 802 ms
65,248 KB
testcase_19 AC 852 ms
65,836 KB
testcase_20 AC 626 ms
63,364 KB
testcase_21 AC 946 ms
65,400 KB
testcase_22 AC 426 ms
61,312 KB
testcase_23 AC 268 ms
61,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q130 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> a = new ArrayList<>();
		for (int i = 0; i < n; ++i) {
			a.add(sc.nextInt());
		}
		System.out.println(dfs(a, 30));
	}

	// Suppose that a is sorted
	static int dfs(ArrayList<Integer> a, int pos) {
		if (pos == -1)
			return 0;
		ArrayList<Integer> one = new ArrayList<>();
		ArrayList<Integer> zero = new ArrayList<>();
		for (int i = 0; i < a.size(); ++i) {
			if ((a.get(i) & (1 << pos)) > 0) {
				one.add(a.get(i));
			} else {
				zero.add(a.get(i));
			}
		}
		int ans = Integer.MAX_VALUE;// 10,11
		if (one.size() == 0) {
			ans = Math.min(ans, dfs(zero, pos - 1));
		} else if (zero.size() == 0) {
			ans = Math.min(ans, dfs(one, pos - 1));
		} else {
			ans = Math.min(ans, dfs(zero, pos - 1) + (1 << pos));
			ans = Math.min(ans, dfs(one, pos - 1) + (1 << pos));
		}
		return ans;
	}
}
0