結果

問題 No.130 XOR Minimax
ユーザー tomoishtomoish
提出日時 2020-01-13 21:43:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 2,368 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 168,324 KB
実行使用メモリ 29,792 KB
最終ジャッジ日時 2023-10-10 00:26:13
合計ジャッジ時間 3,644 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,696 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 49 ms
29,620 KB
testcase_05 AC 55 ms
29,792 KB
testcase_06 AC 47 ms
17,380 KB
testcase_07 AC 50 ms
16,848 KB
testcase_08 AC 35 ms
7,312 KB
testcase_09 AC 9 ms
5,304 KB
testcase_10 AC 15 ms
6,308 KB
testcase_11 AC 52 ms
15,208 KB
testcase_12 AC 5 ms
4,392 KB
testcase_13 AC 43 ms
12,856 KB
testcase_14 AC 44 ms
6,728 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 31 ms
5,444 KB
testcase_17 AC 32 ms
5,508 KB
testcase_18 AC 35 ms
5,868 KB
testcase_19 AC 41 ms
6,700 KB
testcase_20 AC 21 ms
4,736 KB
testcase_21 AC 45 ms
6,752 KB
testcase_22 AC 10 ms
4,352 KB
testcase_23 AC 4 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};



ll solve(ll d,vll& v){
    if(v.size()<2) return 0;
    if(d<0) return 0;
    vll l,r;
    ll n=v.size();
    // cout<<d<<" ";
    // rep(i,n) cout<<v[i]<<" ";
    // cout<<endl;
    rep(i,n){
        if(v[i]&(1ll<<d)) l.pb(v[i]);
        else r.pb(v[i]);
    }
    if(l.size()==0) return solve(d-1,r);
    if(r.size()==0) return solve(d-1,l);
    return (1ll<<d)+min(solve(d-1,r),solve(d-1,l));

}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    ll n;
    cin>>n;
    vll v(n);
    rep(i,n) cin>>v[i];
    cout<<solve(31,v)<<endl;
    return 0;
}
0