# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1136842 | alterio | Unscrambling a Messy Bug (IOI16_messy) | C++20 | 1 ms | 584 KiB |
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> restore_permutation(int n, int w, int r) {
int m = log2(n);
string s = "";
for (int i = 0; i < n; i++) s.push_back('0');
s[0] = '1';
add_element(s);
for (int i = 0; i < n; i++) s[i] = '1';
s[1] = '0';
add_element(s);
for (int i = 0; i < n; i++) s[i] = '0';
s[0] = s[1] = '1';
for (int i = 2; i < m; i++) {
s[i] = '1';
add_element(s);
}
for (int i = m; i < n; i++) {
int l = 0, r = n;
for (int j = 0; j < n; j++) s[j] = '0';
s[i] = '1';
for (int j = 0; j < m; j++) {
if ((1 << j) & i) {
s[j] = '1';
add_element(s);
s[j] = '0';
}
}
}
compile_set();
for (int i = 0; i < n; i++) s[i] = '0';
int pos[m];
bool found[n];
memset(found, 0, sizeof(found));
vector<int> ans(n);
for (int i = 0; i < n; i++) {
s[i] = '1';
if (check_element(s)) {
found[i] = 1;
pos[0] = i;
ans[i] = 0;
break;
}
s[i] = '0';
}
for (int i = 0; i < n; i++) s[i] = '1';
for (int i = 0; i < n; i++) {
if (found[i]) continue;
s[i] = '0';
if (check_element(s)) {
found[i] = 1;
pos[1] = i;
ans[i] = 1;
break;
}
s[i] = '1';
}
for (int i = 0; i < n; i++) s[i] = '0';
for (int i = 0; i < 2; i++) s[pos[i]] = '1';
for (int dig = 2; dig < m; dig++) {
for (int i = 0; i < n; i++) {
if (s[i] == '1') continue;
s[i] = '1';
if (check_element(s)) {
pos[dig] = i;
found[i] = 1;
ans[dig] = i;
break;
}
s[i] = '0';
}
}
for (int i = 0; i < n; i++) s[i] = '0';
for (int i = 0; i < n; i++) {
if (found[i]) continue;
for (int j = 0; j < n; j++) s[j] = '0';
s[i] = '1';
int location = 0;
for (int j = 0; j < m; j++) {
s[pos[j]] = '1';
if (check_element(s)) location += (1 << j);
s[pos[j]] = '0';
}
ans[i] = location;
}
return ans;
}
Compilation message (stderr)
# | 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... |