結果

問題 No.130 XOR Minimax
ユーザー otoshigootoshigo
提出日時 2023-02-20 20:40:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 957 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 75,100 KB
実行使用メモリ 15,876 KB
最終ジャッジ日時 2023-09-28 16:33:55
合計ジャッジ時間 3,707 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 28 ms
15,856 KB
testcase_05 AC 34 ms
15,876 KB
testcase_06 AC 36 ms
9,816 KB
testcase_07 AC 38 ms
9,660 KB
testcase_08 AC 92 ms
4,764 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 14 ms
4,724 KB
testcase_11 AC 43 ms
8,988 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 36 ms
7,820 KB
testcase_14 AC 94 ms
4,624 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 67 ms
4,380 KB
testcase_17 AC 70 ms
4,380 KB
testcase_18 AC 75 ms
4,380 KB
testcase_19 AC 88 ms
4,380 KB
testcase_20 AC 45 ms
4,376 KB
testcase_21 AC 93 ms
4,428 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int f(int d,int N,vector<int>&A){
    if(d<0)return 0;
    vector<int>B,C;
    rep(i,N){
        if(A[i]>>d&1){
            B.push_back(A[i]);
        }else{
            C.push_back(A[i]);
        }
    }
    if(B.empty())return f(d-1,(int)C.size(),C);
    else if(C.empty())return f(d-1,(int)B.size(),B);
    else return (1<<d)^min(f(d-1,(int)C.size(),C),f(d-1,(int)B.size(),B));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin>>N;
    vector<int>A(N);
    rep(i,N)cin>>A[i];
    cout<<f(30,N,A)<<"\n";
}
0