結果

問題 No.130 XOR Minimax
ユーザー chocoruskchocorusk
提出日時 2018-10-15 14:33:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 62,288 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-10 00:23:22
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 19 ms
4,352 KB
testcase_05 AC 43 ms
4,356 KB
testcase_06 AC 30 ms
4,352 KB
testcase_07 AC 41 ms
4,348 KB
testcase_08 AC 48 ms
4,356 KB
testcase_09 AC 7 ms
4,352 KB
testcase_10 AC 10 ms
4,352 KB
testcase_11 AC 32 ms
4,352 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 26 ms
4,376 KB
testcase_14 AC 47 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 33 ms
4,348 KB
testcase_17 AC 34 ms
4,352 KB
testcase_18 AC 37 ms
4,356 KB
testcase_19 AC 44 ms
4,376 KB
testcase_20 AC 22 ms
4,348 KB
testcase_21 AC 48 ms
4,348 KB
testcase_22 AC 11 ms
4,372 KB
testcase_23 AC 5 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int n; int a[100000];
int solve(int i, int l, int r){
    int m=r+1;
    for(int j=l; j<=r; j++){
        if(((a[j]>>i)&1)==1){
            m=j;
            break;
        }
    }
    if(i==0){
        if(m==r+1 || m==l) return 0;
        else return 1;
    }
    if(m==r+1 || m==l) return solve(i-1, l, r);
    return (1<<i)+min(solve(i-1, l, m-1), solve(i-1, m, r));
}

int main(){
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    sort(a, a+n);
    cout<<solve(29, 0, n-1)<<endl;
    return 0;
}
0