Submission #37363836


Source Code Expand

/*
 * File created on 12/17/2022 at 16:57:52.
 * Link to problem: 
 * Description: 
 * Time complexity: O()
 * Space complexity: O()
 * Status: ---
 * Copyright: Ⓒ 2022 Francois Vogel
*/

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pii pair<int, int>
#define f first
#define s second

#define vi vector<int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)((x).size())
#define pb push_back
#define ins insert
#define cls clear

#define int ll
#define ll long long
#define ld long double

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int LOG = 31;

struct Node {
    Node() {
        c = new Node* [2];
        c[0] = c[1] = nullptr;
    }
    void upd(int x, int h = LOG) {
        if (h == -1) return;
        if ((x>>h)&(int)(1)) {
            if (c[1] == nullptr) c[1] = new Node();
            c[1]->upd(x, h-1);
        } else {
            if (c[0] == nullptr) c[0] = new Node();
            c[0]->upd(x, h-1);
        }
    }
    int dp(int h = LOG) {
        if (h == -1) return 0;
        if (c[0] == nullptr) return c[1]->dp(h-1);
        if (c[1] == nullptr) return c[0]->dp(h-1);
        int sA = c[0]->dp(h-1);
        int sB = c[1]->dp(h-1);
        return min(sA, sB) + (1<<h);
    }
    Node** c;
};

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    Node* root = new Node();
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        root->upd(x);
    }
    cout << root->dp();

    cout.flush();
    int d = 0;
    d++;
}

Submission Info

Submission Time
Task F - Xor Minimization
User fvogel
Language C++ (GCC 9.2.1)
Score 500
Code Size 1770 Byte
Status AC
Exec Time 298 ms
Memory 141888 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_srnd_00.txt, 01_srnd_01.txt, 01_srnd_02.txt, 01_srnd_03.txt, 01_srnd_04.txt, 01_srnd_05.txt, 01_srnd_06.txt, 01_srnd_07.txt, 02_rnd_00.txt, 02_rnd_01.txt, 02_rnd_02.txt, 02_rnd_03.txt, 02_rnd_04.txt, 02_rnd_05.txt, 02_rnd_06.txt, 02_rnd_07.txt, 03_same_00.txt, 03_same_01.txt, 03_same_02.txt, 03_same_03.txt, 04_con_00.txt, 04_con_01.txt, 04_con_02.txt, 04_con_03.txt, 04_con_04.txt, 04_con_05.txt, 04_con_06.txt, 04_con_07.txt, 04_con_08.txt, 04_con_09.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 6 ms 3488 KiB
00_sample_01.txt AC 2 ms 3628 KiB
00_sample_02.txt AC 2 ms 3600 KiB
01_srnd_00.txt AC 2 ms 3568 KiB
01_srnd_01.txt AC 3 ms 3504 KiB
01_srnd_02.txt AC 2 ms 3592 KiB
01_srnd_03.txt AC 2 ms 3568 KiB
01_srnd_04.txt AC 2 ms 3624 KiB
01_srnd_05.txt AC 2 ms 3512 KiB
01_srnd_06.txt AC 2 ms 3656 KiB
01_srnd_07.txt AC 2 ms 3640 KiB
02_rnd_00.txt AC 298 ms 134040 KiB
02_rnd_01.txt AC 294 ms 133988 KiB
02_rnd_02.txt AC 298 ms 133956 KiB
02_rnd_03.txt AC 294 ms 133916 KiB
02_rnd_04.txt AC 290 ms 134044 KiB
02_rnd_05.txt AC 294 ms 133988 KiB
02_rnd_06.txt AC 289 ms 134136 KiB
02_rnd_07.txt AC 288 ms 134060 KiB
03_same_00.txt AC 29 ms 3612 KiB
03_same_01.txt AC 25 ms 3584 KiB
03_same_02.txt AC 28 ms 3556 KiB
03_same_03.txt AC 32 ms 3568 KiB
04_con_00.txt AC 57 ms 22384 KiB
04_con_01.txt AC 58 ms 22292 KiB
04_con_02.txt AC 57 ms 22292 KiB
04_con_03.txt AC 56 ms 22320 KiB
04_con_04.txt AC 57 ms 22364 KiB
04_con_05.txt AC 57 ms 22320 KiB
04_con_06.txt AC 60 ms 22396 KiB
04_con_07.txt AC 284 ms 141764 KiB
04_con_08.txt AC 287 ms 141848 KiB
04_con_09.txt AC 284 ms 141888 KiB