結果

問題 No.130 XOR Minimax
ユーザー kimiyukikimiyuki
提出日時 2016-10-21 17:03:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 80,184 KB
実行使用メモリ 98,552 KB
最終ジャッジ日時 2023-10-10 00:14:51
合計ジャッジ時間 5,361 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
44,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 54 ms
4,352 KB
testcase_05 AC 74 ms
4,352 KB
testcase_06 AC 87 ms
15,952 KB
testcase_07 AC 93 ms
16,000 KB
testcase_08 AC 247 ms
98,552 KB
testcase_09 AC 19 ms
6,968 KB
testcase_10 AC 27 ms
8,212 KB
testcase_11 AC 81 ms
12,564 KB
testcase_12 AC 10 ms
5,544 KB
testcase_13 AC 64 ms
11,772 KB
testcase_14 AC 275 ms
79,864 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 194 ms
58,408 KB
testcase_17 AC 198 ms
60,640 KB
testcase_18 AC 215 ms
64,644 KB
testcase_19 AC 254 ms
75,304 KB
testcase_20 AC 123 ms
40,144 KB
testcase_21 AC 281 ms
79,400 KB
testcase_22 AC 58 ms
21,416 KB
testcase_23 AC 14 ms
9,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <memory>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
struct tree_t {
    shared_ptr<tree_t> left, right;
};
shared_ptr<tree_t> insert(shared_ptr<tree_t> t, int32_t x, int i) {
    if (not t) t = make_shared<tree_t>();
    if (i == -1) return t;
    shared_ptr<tree_t> & nt = (x & (1 << i) ? t->right : t->left);
    nt = insert(nt, x, i-1);
    return t;
}
int dfs(shared_ptr<tree_t> const & t, int i) {
    return
        not t ? 0 :
        not t->left  ? dfs(t->right, i-1) :
        not t->right ? dfs(t->left, i-1) :
        min(dfs(t->left, i-1), dfs(t->right, i-1)) + (1 << i);
}
int main() {
    int n; cin >> n;
    vector<int32_t> a(n); repeat (i,n) cin >> a[i];
    shared_ptr<tree_t> root = nullptr;
    repeat (i,n) root = insert(root, a[i], 31);
    cout << dfs(root, 31) << endl;
    return 0;
}
0