#include <iostream>
#include <vector>
using namespace std;
#include "messy.h"
int n;
char s[200];
vector<int> ans;
void add(int l, int r) {
if (l == r) return;
int mid = (l+r)/2;
for (int i = 0; i < n; i++) s[i] = '1';
for (int i = l; i <= r; i++) s[i] = '0';
for (int i = l; i <= mid; i++) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
add(l,mid); add(mid+1,r);
}
void solve(int l, int r, vector<int> can) {
if (l == r) {
ans.push_back(can[0]);
return;
}
vector<int> ll, rr;
for (int i = 0; i < n; i++) s[i] = '1';
for (int i = 0; i < can.size(); i++) s[can[i]] = '0';
for (int i = 0; i < can.size(); i++) {
s[can[i]] = '1';
if (check_element(s)) ll.push_back(can[i]);
else rr.push_back(can[i]);
s[can[i]] = '0';
}
int mid = (l+r)/2;
solve(l,mid,ll); solve(mid+1,r,rr);
}
std::vector<int> restore_permutation(int N, int w, int r) {
n = N;
add(0,n-1);
compile_set();
vector<int> can;
for (int i = 0; i < n; i++) can.push_back(i);
solve(0,n-1,can);
vector<int> res(n);
for (int i = 0; i < n; i++) res[ans[i]] = i;
return res;
}
Compilation message (stderr)
messy.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
messy_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |