結果
問題 | No.130 XOR Minimax |
ユーザー |
![]() |
提出日時 | 2020-01-28 10:40:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 75 ms / 5,000 ms |
コード長 | 1,238 bytes |
コンパイル時間 | 1,946 ms |
コンパイル使用メモリ | 171,028 KB |
実行使用メモリ | 23,820 KB |
最終ジャッジ日時 | 2024-09-12 22:55:13 |
合計ジャッジ時間 | 3,509 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i = 0; i < (n); ++i)#define srep(i,s,t) for (int i = s; i < t; ++i)#define drep(i,n) for(int i = (n)-1; i >= 0; --i)using namespace std;typedef long long int ll;typedef pair<int,int> P;#define yn {puts("Yes");}else{puts("No");}#define MAX_N 100005int n;ll a[MAX_N];int f[MAX_N][50];const ll INF = 1234567812345;ll two[50];ll dfs(int l, int r, int d, ll res){if(l == r)return INF;int m = -1;srep(i,l,r){if(f[i][d] == 1 && m == -1){m = i;}}if(m == -1) m = r;if(d == 0){if(m == l || m == r){return res;}else{return res + 1;}}if(m == l){return dfs(l,r,d-1,res);}else if(m == r){return dfs(l,r,d-1,res);}else{res += two[d];return min(dfs(l,m,d-1,res), dfs(m,r,d-1,res));}}int main() {cin >> n;rep(i,n)cin >> a[i];sort(a,a+n);rep(i,n){ll a_ = a[i];rep(j,50){f[i][j] = a_ % 2;a_ /= 2;}}two[0] = 1;srep(i,1,50)two[i] = two[i-1] * 2;ll ans = dfs(0, n, 40, 0);cout << ans << endl;return 0;}