結果

問題 No.130 XOR Minimax
ユーザー snrnsidysnrnsidy
提出日時 2021-05-23 03:50:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 600 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 199,664 KB
実行使用メモリ 16,208 KB
最終ジャッジ日時 2024-04-19 11:23:01
合計ジャッジ時間 4,308 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 28 ms
16,208 KB
testcase_05 AC 37 ms
16,208 KB
testcase_06 AC 36 ms
9,940 KB
testcase_07 AC 40 ms
9,816 KB
testcase_08 AC 97 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 14 ms
5,376 KB
testcase_11 AC 41 ms
8,960 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 34 ms
7,832 KB
testcase_14 AC 95 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 69 ms
5,376 KB
testcase_17 AC 71 ms
5,376 KB
testcase_18 AC 77 ms
5,376 KB
testcase_19 AC 91 ms
5,376 KB
testcase_20 AC 47 ms
5,376 KB
testcase_21 AC 95 ms
5,376 KB
testcase_22 AC 23 ms
5,376 KB
testcase_23 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

vector<int> a;
int f(vector<int>& v, int bit) {
    if (v.empty() || bit < 0) return 0LL;

    vector<int> l, r;
    for (int& x : v) {
        if ((x >> bit) & 1) r.push_back(x);
        else l.push_back(x);
    }

    if (l.empty() || r.empty()) return f(l.empty() ? r : l, bit - 1);
    else return min(f(l, bit - 1), f(r, bit - 1)) | (1 << bit);
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    a.clear(); a.resize(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i];

    printf("%d", f(a, 30));
    return 0;
}
0