結果
問題 | No.130 XOR Minimax |
ユーザー |
|
提出日時 | 2016-11-25 00:19:47 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,029 ms / 5,000 ms |
コード長 | 985 bytes |
コンパイル時間 | 3,930 ms |
コンパイル使用メモリ | 79,280 KB |
実行使用メモリ | 75,472 KB |
最終ジャッジ日時 | 2024-09-12 22:43:08 |
合計ジャッジ時間 | 20,342 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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 sortedstatic 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,11if (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;}}