1 条题解

  • 0
    @ 2025-10-14 9:15:05
    #include <bits/stdc++.h>
    using namespace std;
    int n;
    string s;
    int tot = 2;
    int t[4000000][2];
    int a[100020];
    void add(int c) {
        int h = 1;
        for (int i = 30; i > -1; i--) {
            int ci = (c >> i) & 1;
            if (t[h][ci] <= 0) {
                t[h][ci] = tot;
                tot++;
            }
            h = t[h][ci];
        }
        return;
    }
    int query(int c) {
        int h = 1;
        int sum = 0;
        for (int i = 30; i > -1; i--) {
            int ci = (c >> i) & 1;
            if (t[h][1 - ci] > 1) {
                sum += (1 << i);
                h = t[h][1 - ci];
            } else {
                h = t[h][ci];
            }
        }
        return sum;
    }
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            add(a[i]);
        }
        int maxl = 0;
        for (int i = 0; i < n; i++) {
            maxl = max(maxl, query(a[i]));
        }
        cout << maxl;
        return 0;
    }
    
    • 1

    信息

    ID
    1182
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者