7 条题解

  • 0
    @ 2024-6-23 8:27:14
    #include <bits/stdc++.h>
    using namespace std;
    
    int n, a[1000005], t[10000005][2], p = 1, ans;
    
    void insert(int u, int x, int b) {
        if (!x) return;
        int j = (x >> b) & 1;
        if (!t[u][j]) t[u][j] = ++p;
        insert(t[u][j], x - (j << b), b - 1);
    }
    
    int search(int u, int x) {
        int res = 0;
        for (int i = 30; i >= 0; i--) {
            if (!u) break;
            int j = (x >> i) & 1;
            t[u][!j] ? res += 1 << i, u = t[u][!j] : u = t[u][j];
        }
        return res;
    }
    
    int main() {
        cin >> n;
        for (int i = 0; i < n; i++) scanf("%d", &a[i]), insert(1, a[i], 30);
        for (int i = 0; i < n; i++) ans = max(ans, search(1, a[i]));
        cout << ans;
        return 0;
    }
    

    信息

    ID
    94
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    714
    已通过
    166
    上传者