結果

問題 No.130 XOR Minimax
ユーザー hogeover30hogeover30
提出日時 2016-08-24 20:42:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 603 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 75,900 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-10 00:14:34
合計ジャッジ時間 2,128 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 12 ms
4,352 KB
testcase_05 AC 18 ms
4,348 KB
testcase_06 AC 14 ms
4,348 KB
testcase_07 AC 17 ms
4,348 KB
testcase_08 AC 21 ms
4,348 KB
testcase_09 AC 4 ms
4,352 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 3 ms
4,352 KB
testcase_13 AC 15 ms
4,348 KB
testcase_14 AC 24 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 17 ms
4,352 KB
testcase_17 AC 18 ms
4,356 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 22 ms
4,352 KB
testcase_20 AC 11 ms
4,348 KB
testcase_21 AC 24 ms
4,348 KB
testcase_22 AC 6 ms
4,352 KB
testcase_23 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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