結果

問題 No.130 XOR Minimax
ユーザー ゆきのんゆきのん
提出日時 2020-03-12 05:14:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 1,566 bytes
コンパイル時間 1,910 ms
コンパイル使用メモリ 170,668 KB
実行使用メモリ 28,968 KB
最終ジャッジ日時 2023-10-10 00:27:47
合計ジャッジ時間 4,204 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
5,696 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 10 ms
5,516 KB
testcase_05 AC 39 ms
28,968 KB
testcase_06 AC 40 ms
8,852 KB
testcase_07 AC 52 ms
18,604 KB
testcase_08 AC 100 ms
8,772 KB
testcase_09 AC 11 ms
4,372 KB
testcase_10 AC 15 ms
4,716 KB
testcase_11 AC 45 ms
8,084 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 38 ms
7,152 KB
testcase_14 AC 100 ms
7,708 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 71 ms
6,356 KB
testcase_17 AC 73 ms
6,624 KB
testcase_18 AC 80 ms
6,868 KB
testcase_19 AC 95 ms
7,680 KB
testcase_20 AC 47 ms
5,372 KB
testcase_21 AC 100 ms
7,876 KB
testcase_22 AC 23 ms
4,348 KB
testcase_23 AC 8 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};
 
LL rec(int k,vector<LL> a){
    if(k==-1) return 0;
    int n = a.size();
    bool z = false,o = false;
    for (int i = 0; i < n; i++) {
        if((a[i]>>k)&1) o = true;
        else z = true;
    }
    if(!o){
        return rec(k-1,a);
    }
    else if(!z){
        for (int i = 0; i < n; i++) {
            a[i] ^= 1LL << k;
        }
        return rec(k-1,a);
    }
    else{
        vector<LL> p,q;
        for (int i = 0; i < n; i++) {
            if((a[i] >> k)&1) p.pb(a[i] ^ (1LL << k));
            else q.pb(a[i]);
        }
        return min(rec(k-1,p), rec(k-1,q)) + (1LL << k);
    }
}
 
 
int main(){
    int n;cin >> n;
    vector<LL> a(n);
    int k = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lld",&a[i]);
        LL t = a[i];
        int cnt = 0;
        while(t){
            t >>= 1;
            cnt++;
        }
        k = max(k, cnt);
    }
    cout << rec(k,a) << endl;
    return 0;
}
0