結果
| 問題 |
No.130 XOR Minimax
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-05 15:46:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 5,000 ms |
| コード長 | 726 bytes |
| コンパイル時間 | 807 ms |
| コンパイル使用メモリ | 59,524 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-12 22:35:11 |
| 合計ジャッジ時間 | 2,146 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <algorithm>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
const double EPS=1e-9;
int a[100100];
const int inf = 0x7ff00000;
int rec(int s, int t, int b) {
if (b < 0) {
return 0;
}
if (s >= t) {
return inf;
}
if ((a[s] & (1 << b)) == (a[t - 1] & (1 << b))) {
return rec(s, t, b - 1);
}
int i = s;
while (i < t) {
if (a[i] & (1 << b)) {
break;
}
i ++;
}
// [s,i), [i,t)
int r1 = rec(s, i, b - 1);
int r2 = rec(i, t, b - 1);
return min(r1, r2) + (1 << b);
}
int main(void){
int n;
cin >> n;
REP(i, 0, n) {
cin >> a[i];
}
sort(a, a + n);
cout << rec(0, n, 30) << endl;
}