結果

問題 No.130 XOR Minimax
ユーザー okadukiokaduki
提出日時 2015-01-17 01:24:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,083 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 92,848 KB
実行使用メモリ 28,572 KB
最終ジャッジ日時 2023-09-04 15:08:19
合計ジャッジ時間 2,759 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 43 ms
28,552 KB
testcase_05 AC 49 ms
28,572 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1234567890;

VI a;
int solve(int d, VI num, int bit){
  //  cout << d << ":" << num[0] << "," << bit << endl;
  if(d < 0) return a[num[0]]^bit;
  if(SZ(num) == 1)
	return (a[num[0]] & ~((1<<d)-1))^bit;

  VI t[2];
  REP(i,SZ(num)){
	t[a[num[i]]>>d&1].PB(i);
  }

  if(SZ(t[0]) == 0)
	return solve(d-1, t[1], bit|(1<<d));
  if(SZ(t[1]) == 0)
	return solve(d-1, t[0], bit);

  //int r1= solve(d-1, t[0], bit|(1<<d)), r2 = solve(d-1, t[1], bit);
  //cout << d << ":" << r1 << "," << r2 << endl;
  return min(solve(d-1, t[0], bit|(1<<d)), solve(d-1, t[1], bit));
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  a.assign(N,0);
  REP(i,N) cin >> a[i];

  VI t;
  REP(i,N) t.PB(i);
  cout << solve(30, t, 0) << endl;
  
  return 0;
}
0