結果

問題 No.130 XOR Minimax
ユーザー ShibuyapShibuyap
提出日時 2020-01-28 10:40:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 1,238 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 169,348 KB
実行使用メモリ 23,984 KB
最終ジャッジ日時 2023-10-10 00:26:41
合計ジャッジ時間 3,874 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
14,240 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 46 ms
23,712 KB
testcase_05 AC 73 ms
23,792 KB
testcase_06 AC 57 ms
23,708 KB
testcase_07 AC 66 ms
23,856 KB
testcase_08 AC 73 ms
23,984 KB
testcase_09 AC 11 ms
7,556 KB
testcase_10 AC 16 ms
9,716 KB
testcase_11 AC 54 ms
20,656 KB
testcase_12 AC 6 ms
4,832 KB
testcase_13 AC 42 ms
18,196 KB
testcase_14 AC 68 ms
20,372 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 47 ms
16,076 KB
testcase_17 AC 49 ms
16,100 KB
testcase_18 AC 53 ms
18,180 KB
testcase_19 AC 64 ms
20,660 KB
testcase_20 AC 31 ms
12,024 KB
testcase_21 AC 69 ms
20,440 KB
testcase_22 AC 16 ms
7,640 KB
testcase_23 AC 6 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 100005

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