結果

問題 No.130 XOR Minimax
ユーザー koba-e964koba-e964
提出日時 2015-06-05 15:37:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,045 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 79,876 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-10 00:08:29
合計ジャッジ時間 2,235 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 14 ms
4,372 KB
testcase_05 AC 37 ms
4,372 KB
testcase_06 AC 28 ms
4,372 KB
testcase_07 AC 38 ms
4,372 KB
testcase_08 AC 39 ms
4,368 KB
testcase_09 AC 6 ms
4,368 KB
testcase_10 AC 9 ms
4,372 KB
testcase_11 AC 29 ms
4,368 KB
testcase_12 AC 4 ms
4,372 KB
testcase_13 AC 21 ms
4,372 KB
testcase_14 AC 37 ms
4,372 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 26 ms
4,372 KB
testcase_17 AC 27 ms
4,376 KB
testcase_18 AC 30 ms
4,372 KB
testcase_19 AC 35 ms
4,372 KB
testcase_20 AC 17 ms
4,368 KB
testcase_21 AC 37 ms
4,372 KB
testcase_22 AC 8 ms
4,372 KB
testcase_23 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
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;
}
0