# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
355605 | thecodingwizard | Robots (APIO13_robots) | C++11 | 0 ms | 0 KiB |
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;
void addStuff(int n, string pref, string suff) {
if (n == 1) return;
for (int i = n/2; i < n; i++) {
string s;
for (int j = 0; j < n; j++) {
if (j == i) s += "1";
else s += "0";
}
add_element(pref + s + suff);
}
string halfZeroes; for (int i = 0; i < n/2; i++) halfZeroes += "1";
addStuff(n/2, pref+halfZeroes, suff);
addStuff(n/2, pref, halfZeroes+suff);
}
void checkStuff(vector<int> &perm, int n, vector<int> indices, int lo, int hi) {
if (indices.size() == 1) {
perm[indices[0]] = lo;
return;
}
string s; for (int i = 0; i < n; i++) s += "1";
for (auto x : indices) s[x] = '0';
vector<int> leftHalf;
vector<int> rightHalf;
for (auto x : indices) {
s[x] = '1';
if (check_element(s)) {
rightHalf.push_back(x);
} else {
leftHalf.push_back(x);
}
s[x] = '0';
}
checkStuff(perm, n, leftHalf, lo, (lo+hi)/2);
checkStuff(perm, n, rightHalf, (lo+hi)/2+1, hi);
}
vector<int> restore_permutation(int n, int w, int r) {
addStuff(n, "", "");
compile_set();
vector<int> perm(n);
vector<int> indices(n); iota(indices.begin(), indices.end(), 0);
checkStuff(perm, n, indices, 0, n-1);
return perm;
}