結果
| 問題 |
No.130 XOR Minimax
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-24 19:23:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,684 bytes |
| コンパイル時間 | 3,871 ms |
| コンパイル使用メモリ | 78,060 KB |
| 実行使用メモリ | 66,640 KB |
| 最終ジャッジ日時 | 2024-11-27 10:47:09 |
| 合計ジャッジ時間 | 21,125 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 4 |
ソースコード
package yukicoder;
import java.util.*;
public class Q130 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; ++i) {
a[i] = sc.nextLong();
}
Arrays.sort(a);
/*
* long ans = 0; for (int t = 0; t < 100; ++t) { for (long i = 32; i >=
* 0; --i) {// 3=1,1, if ((a[n - 1] & (1L << i)) > 0) { long[] tmp =
* Arrays.copyOf(a, n); long tmpMax = 0; for (int j = 0; j < n; ++j) {
* tmp[j] = a[j] ^ (1L << i); tmpMax = Math.max(tmpMax, tmp[j]); } if
* (tmpMax < a[n - 1]) { if ((ans & (1L << i)) > 0) throw new
* AssertionError(); ans |= 1L << i; a = tmp; Arrays.sort(a); break; } }
* } }
*/
System.out.println(dfs(a, 0));
// System.out.println(a[n - 1]);
}
// Suppose that a is sorted
static long dfs(long[] a, long p) {
int n = a.length;
long min = a[n - 1];
boolean f = true;
while (f) {
long dumy = a[n - 1];
outer:for (long i = 32; i >= 0; --i) {// 3=1,1,
if ((a[n - 1] & (1L << i)) > 0 && ((p & (1L << i)) == 0)) {
long[] tmp = Arrays.copyOf(a, n);
long tmpMax = 0;
for (int j = 0; j < n; ++j) {
tmp[j] = a[j] ^ (1L << i);
tmpMax = Math.max(tmpMax, tmp[j]);
}
if (tmpMax < a[n - 1]) {
if ((p & (1L << i)) > 0)
throw new AssertionError();
p |= 1L << i;
a = tmp;
Arrays.sort(a);
break outer;
} else if (tmpMax == a[n - 1]) {
long[] next = Arrays.copyOf(tmp, n);
Arrays.sort(next);
min = Math.min(dfs(next, p | (1L << i)), min);
}
}
}
if (dumy == a[n - 1])
f = false;
}
return Math.min(min, a[n - 1]);
}
}