結果
問題 | No.130 XOR Minimax |
ユーザー |
![]() |
提出日時 | 2019-06-13 22:07:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 213 ms / 5,000 ms |
コード長 | 1,436 bytes |
コンパイル時間 | 994 ms |
コンパイル使用メモリ | 105,280 KB |
実行使用メモリ | 42,928 KB |
最終ジャッジ日時 | 2024-09-12 22:52:49 |
合計ジャッジ時間 | 4,020 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include <cstdlib> #include <math.h> #include <cmath> #include<cctype> #include<string> #include<set> #include<iomanip> #include <map> #include<algorithm> #include <functional> #include<vector> #include<climits> #include<stack> #include<queue> #include<bitset> #include <deque> #include <climits> #include <typeinfo> #include <utility> using namespace std; using ll = long long; using R = double; using Data = pair < ll, vector <ll>>; template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 60; struct edge { ll from; ll to; ll cost; }; typedef pair<ll, ll>pll; #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(ll i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(ll i = m;i >= n;--i) #define INF INT_MAX/2 vector<ll>v; set<ll>st; ll N; ll calc(ll d, vector<ll>li) { if (d == -1)return 0; vector<ll>w[2]; rep(i, 0, li.size()) { ll x = li[i]; if (x & (1LL << d)) { w[1].pb(x^(1LL<<d)); } else { w[0].pb(x); } } if (w[0].size() == 0)return calc(d-1,w[1]); if (w[1].size() == 0)return calc(d-1,w[0]); ll ret = 1LL << d; ret += min(calc(d-1,w[0]), calc(d-1,w[1])); return ret; } int main(){ cin >> N; rep(i, 0, N) { ll x; cin >> x; st.insert(x); } fore(x, st)v.pb(x); cout << calc(35,v) << endl; return 0; }