結果
| 問題 |
No.130 XOR Minimax
|
| コンテスト | |
| ユーザー |
hogeover30
|
| 提出日時 | 2016-08-24 20:42:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 5,000 ms |
| コード長 | 603 bytes |
| コンパイル時間 | 678 ms |
| コンパイル使用メモリ | 74,932 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-12 22:40:54 |
| 合計ジャッジ時間 | 1,904 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int func(vector<int>& a, int l, int r, int k)
{
if (r-l<1) return 1<<30;
if (k<0) return 0;
int x=0, nr=r;
for(int i=l+1; i<r; ++i) {
if ((a[i]&(1<<k))!=(a[i-1]&(1<<k))) {
x=(1<<k);
nr=i;
break;
}
}
return x+min(func(a, l, nr, k-1), func(a, nr, r, k-1));
}
int main()
{
cin.sync_with_stdio(0);
cin.tie(0);
int n; cin>>n;
vector<int> a(n); for(auto& e: a) cin>>e;
sort(begin(a), end(a));
cout<<func(a, 0, n, 30)<<endl;
}
hogeover30