結果

問題 No.130 XOR Minimax
ユーザー GOTKAKO
提出日時 2025-07-13 05:18:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 751 bytes
コンパイル時間 2,230 ms
コンパイル使用メモリ 198,764 KB
実行使用メモリ 27,464 KB
最終ジャッジ日時 2025-07-13 05:19:04
合計ジャッジ時間 4,772 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

    int N; cin >> N;
    vector<int> A(N);
    for(auto &a : A) cin >> a;
    int answer = 0;
    auto solve = [&](auto solve,vector<int> A,int d) -> int {
        if(d < 0) return 0;
        vector<int> zero,one;
        for(auto a : A){
            if(a&(1<<d)) one.push_back(a-(1<<d));
            else zero.push_back(a);
        }
        if(zero.size() && one.size()){
            int ret = 1<<d;
            return ret+min(solve(solve,zero,d-1),solve(solve,one,d-1));
        }
        else if(one.size()) return solve(solve,one,d-1);
        else return solve(solve,zero,d-1);
    };
    cout << solve(solve,A,29) << endl;
}
0