結果

問題 No.130 XOR Minimax
ユーザー IKyoproIKyopro
提出日時 2020-01-11 01:35:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 959 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 206,248 KB
実行使用メモリ 814,592 KB
最終ジャッジ日時 2024-05-03 02:07:46
合計ジャッジ時間 3,926 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N);
    int h = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        for(int j=0;j<30;j++) if(A[i]&(1<<j)) h = j;
    }

    auto calc = [&](auto&& self,vec<ll> A,int bit)->ll{
        bool ok = true;
        int n = A.size();
        if(n<=1) return 0;
        ll a = -1;
        vec<ll> X,Y;
        for(int i=0;i<n;i++){
            if(A[i]&(1<<bit)) X.push_back(A[i]%(1<<bit));
            else Y.push_back(A[i]%(1<<bit));
        }
        if(X.empty() || Y.empty()) return (X.empty()? self(self,Y,bit-1):self(self,X,bit-1));
        else return (1<<bit) + min(self(self,X,bit-1),self(self,Y,bit-1));
    };
    cout << calc(calc,A,h) << endl;
}
0