# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1247716 | m_bezrutchka | Unscrambling a Messy Bug (IOI16_messy) | C++20 | 0 ms | 0 KiB |
#include <vector>
#include "messy.h"
using namespace std;
vector<int> restore_permutation(int n, int w, int r) {
string s = "";
for (int i = 0; i < n; i++) {
s.push_back('0');
}
for (int i = 0; i < n; i++) {
s[i] = '1';
add_element(s);
}
compile_set();
for (int i = 0; i < n; i++) {
s[i] = '0';
}
int first_idx = -1;
for (int i = 0; i < n; i++) {
s[i] = '1';
if (!check_element(s)) {
first_idx = i;
break;
}
}
vector<int> p;
for (int i = 0; i < n; i++) {
p.push_back(i);
}
// identity case
if (first_idx == -1) return p;
s[first_idx] = '0';
int second_idx = -1;
for (int i = first_idx + 1; i < n; i++) {
s[i] = '1';
if (check_element(s)) {
second_idx = i;
break;
}
s[i] = '0';
}
assert(second_idx != -1);
swap(p[first_idx], p[second_idx]);
return p;
}