結果

問題 No.130 XOR Minimax
ユーザー pekempeypekempey
提出日時 2015-08-20 19:55:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 776 bytes
コンパイル時間 1,258 ms
コンパイル使用メモリ 147,740 KB
実行使用メモリ 28,184 KB
最終ジャッジ日時 2023-10-10 00:10:06
合計ジャッジ時間 4,188 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
4,660 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 43 ms
28,136 KB
testcase_05 AC 66 ms
28,184 KB
testcase_06 AC 55 ms
16,444 KB
testcase_07 AC 67 ms
16,036 KB
testcase_08 AC 150 ms
6,252 KB
testcase_09 AC 13 ms
5,464 KB
testcase_10 AC 19 ms
6,136 KB
testcase_11 AC 60 ms
14,248 KB
testcase_12 AC 7 ms
4,372 KB
testcase_13 AC 50 ms
12,256 KB
testcase_14 AC 139 ms
5,704 KB
testcase_15 AC 4 ms
4,480 KB
testcase_16 AC 102 ms
5,048 KB
testcase_17 AC 103 ms
4,884 KB
testcase_18 AC 110 ms
5,276 KB
testcase_19 AC 130 ms
5,596 KB
testcase_20 AC 71 ms
4,376 KB
testcase_21 AC 136 ms
5,784 KB
testcase_22 AC 31 ms
4,352 KB
testcase_23 AC 10 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

int N;

int dfs(int k, vector<int> A) {
	if (k < 0) return 0;
	vector<int> X, Y;
	rep (i, A.size()) {
		if (A[i] & 1 << k) {
			X.push_back(A[i]);
		} else {
			Y.push_back(A[i]);
		}
	}
	if (X.size() == 0 || Y.size() == 0) {
		return dfs(k - 1, A);
	} else {
		return min(dfs(k - 1, X), dfs(k - 1, Y)) + (1 << k);
	}
}

int main() {
    cin >> N;
    vector<int> A(N);
    rep (i, N) cin >> A[i];

    cout << dfs(30, A) << endl;

    return 0;
}
0