Submission #230784

#TimeUsernameProblemLanguageResultExecution timeMemory
230784arborUnscrambling a Messy Bug (IOI16_messy)C++14
Compilation error
0 ms0 KiB
#include "messy.h"

#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define lc (i << 1)
#define rc (i << 1 | 1)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f, BSZ = 320;

/*
void add_element(string x);
void compile_set();
bool check_element(string x);
*/

/*
 * Inserting the strings in a special way, we can use divide and conquer to restore the permutation.
 * We can insert them based on the range that each string will conver, if a string covers the range from
 * [l, r] we first fill [l, r] with 0s (Note that the rest of the string will be 1s to act as placeholders).
 * Then, for each idx from [l, m] we toggle the bit and insert. Therefore, we can use these strings to find
 * the indexes that [l, m] map to. Once we have found this range, the elements that were not used correspond
 * to the other range, [m + 1, r]. We can continue recursing on these to recover the permutation.
 */

int N, ret[128];

void init(int l, int r) {
    if (l == r) return;
    string s(N, '1');
    for (int i = l; i <= r; i++) s[i] = '0';
    int m = (l + r) / 2;
    for (int i = l; i <= m; i++) {
        s[i] = '1';
        add_element(s);
        s[i] = '0';
    }
    init(l, m);
    init(m + 1, r);
}

void go(int l, int r, vector<int> cur) {
    if (l == r) {
        ret[cur[0]] = l;
        return;
    }
    string s(N, '1');
    for (int i : cur) s[i] = '0';
    vector<int> left, right;
    for (int i : cur) {
        s[i] = '1';
        if (check_element(s)) left.push_back(i);
        else right.push_back(i);
        s[i] = '0';
    }
    int m = (l + r) / 2;
    go(l, m, left);
    go(m + 1, r, right);
}

int *restore_permutation(int n, int w, int r) {
    N = n;
    init(0, N - 1);
    compile_set();
    vector<int> cur;
    for (int i = 0; i < N; i++) cur.push_back(i);
    go(0, N - 1, cur);
    return ret;
}

Compilation message (stderr)

messy.cpp: In function 'int* restore_permutation(int, int, int)':
messy.cpp:63:6: error: ambiguating new declaration of 'int* restore_permutation(int, int, int)'
 int *restore_permutation(int n, int w, int r) {
      ^~~~~~~~~~~~~~~~~~~
In file included from messy.cpp:1:0:
messy.h:10:18: note: old declaration 'std::vector<int> restore_permutation(int, int, int)'
 std::vector<int> restore_permutation(int n, int w, int r);
                  ^~~~~~~~~~~~~~~~~~~