# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
230783 | arbor | Unscrambling a Messy Bug (IOI16_messy) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}