結果

問題 No.130 XOR Minimax
ユーザー tottoripapertottoripaper
提出日時 2019-03-08 15:25:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 965 bytes
コンパイル時間 1,611 ms
コンパイル使用メモリ 167,268 KB
実行使用メモリ 15,720 KB
最終ジャッジ日時 2023-10-10 00:24:04
合計ジャッジ時間 3,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 27 ms
15,720 KB
testcase_05 AC 31 ms
15,532 KB
testcase_06 AC 31 ms
9,460 KB
testcase_07 AC 34 ms
9,312 KB
testcase_08 AC 87 ms
4,348 KB
testcase_09 AC 8 ms
4,352 KB
testcase_10 AC 10 ms
4,552 KB
testcase_11 AC 32 ms
8,556 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 28 ms
7,404 KB
testcase_14 AC 75 ms
4,464 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 55 ms
4,348 KB
testcase_17 AC 57 ms
4,352 KB
testcase_18 AC 61 ms
4,348 KB
testcase_19 AC 70 ms
4,352 KB
testcase_20 AC 38 ms
4,352 KB
testcase_21 AC 74 ms
4,348 KB
testcase_22 AC 19 ms
4,352 KB
testcase_23 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;

int f(int i, std::vector<int> &&A){
    if(i < 0){
        return 0;
    }

    std::vector<int> B[2];

    for(int a : A){
        B[a >> i & 1].emplace_back(a);
    }

    if(B[0].size() == 0){
        return f(i - 1, std::move(B[1]));
    }

    if(B[1].size() == 0){
        return f(i - 1, std::move(B[0]));
    }

    int x0 = f(i - 1, std::move(B[0])), x1 = f(i - 1, std::move(B[1]));
    return std::min(std::max((1 << i) + x0, x1), std::max(x0, (1 << i) + x1));
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    std::vector<int> A(N);

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    int x = f(29, std::move(A));
    std::cout << x << std::endl;
}
0