This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
const int N = 128;
int n;
int res[N];
bool a[N];
void add() {
string s;
for (int i = 0; i < n; ++i) {
s.push_back(a[i] + '0');
}
// cout << "add " << s << '\n';
add_element(s);
}
bool check() {
string s;
for (int i = 0; i < n; ++i) {
s.push_back(a[i] + '0');
}
// cout << "check " << s << '\n';
return check_element(s);
}
void add(int p, vector<int> vecx, vector<int> vecy) {
if (vecx.size() == 1) return;
vector<int> vec0, vec1;
for (auto i : vecx) {
if ((i / (1 << p)) & 1) {
memset(a, 0, sizeof a);
a[i] = 1;
for (auto j : vecy) a[j] = 1;
add();
vec1.push_back(i);
}
else vec0.push_back(i);
}
add(p + 1, vec0, vec1);
add(p + 1, vec1, vec0);
}
void check(int p, int mask, vector<int> vecx, vector<int> vecy) {
if (vecx.size() == 1) {
res[vecx[0]] = mask; return;
}
vector<int> vec0, vec1;
for (auto i : vecx) {
memset(a, 0, sizeof a);
a[i] = 1;
for (auto j : vecy) a[j] = 1;
if (check()) vec1.push_back(i);
else vec0.push_back(i);
}
check(p + 1, mask, vec0, vec1);
check(p + 1, mask | (1 << p), vec1, vec0);
}
vector<int> restore_permutation(int _n, int w, int r) {
n = _n;
int m = 0;
while ((1 << m) != n) m++;
vector<int> vec0, vec1;
for (int i = 0; i < n; i += 2) {
vec0.push_back(i);
}
for (int i = 1; i < n; i += 2) {
memset(a, 0, sizeof a);
a[i] = 1, add();
vec1.push_back(i);
}
add(1, vec0, vec1);
add(1, vec1, vec0);
compile_set();
vec0.clear(), vec1.clear();
for (int i = 0; i < n; ++i) {
memset(a, 0, sizeof a);
a[i] = 1;
if (check()) vec1.push_back(i);
else vec0.push_back(i);
}
check(1, 0, vec0, vec1);
check(1, 1, vec1, vec0);
vector<int> vec;
for (int i = 0; i < n; ++i) vec.push_back(res[i]);
return vec;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |