結果

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

テストケース

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

ソースコード

diff #

#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;
}
0