#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
#define ll long long
//#define endl "\n"
const int MOD = 998244353;
/*void add_element(string x);
void compile_set();
bool check_element(string x);*/
void add_lg(int n, int lg){
string s = "";
for(int i = 0; i < n; i++) s += '0';
s[0] = '1';
s[1] = '1';
add_element(s);
s[1] = '0';
s[2] = '1';
s[3] = '1';
add_element(s);
s[1] = '1';
s[2] = '0';
s[3] = '0';
for(int i = 2; i < lg; i++){
s[i] = '1';
add_element(s);
}
}
void check_lg(int n, int lg, vector<int>& possible, vector<int>& ind){
string s = "";
for(int i = 0; i < n; i++) s += '0';
pair<int, int> initial = {-1, -1};
for(int i = 0; i < lg && initial.first == -1; i++){
for(int j = i + 1; j < lg && initial.first == -1; j++){
for(int q = 0; q < lg; q++) s[possible[q]] = '0';
s[possible[i]] = '1';
s[possible[j]] = '1';
bool rep = check_element(s);
if(rep){
initial = {i, j};
}
}
}
for(int i = 2; i < lg; i++){
for(int j = 0; j < lg; j++){
for(int q = 0; q < lg; q++) s[possible[q]] = '0';
for(int q = i - 1; q >= 2; q--) s[ind[q]] = '1';
s[initial.first] = '1';
s[initial.second] = '1';
if(s[possible[j]] == '1') continue;
else if(i == lg - 1){
for(int x : possible){
if(s[x] == '0') ind[i] = x;
}
break;
}
s[possible[j]] = '1';
bool rep = check_element(s);
if(rep){
ind[i] = possible[j];
break;
}
}
}
for(int q = 0; q < lg; q++) s[possible[q]] = '0';
s[initial.first] = '1';
s[ind[2]] = '1';
s[ind[3]] = '1';
bool rep = check_element(s);
if(rep) {ind[0] = initial.first; ind[1] = initial.second;}
else {ind[1] = initial.first; ind[0] = initial.second;}
}
vector<int> restore_permutation(int n, int w, int r){
int lg = 0;
int curr = 1;
while(curr < n){
lg++;
curr *= 2;
}
vector<vector<bool>> v(n, vector<bool>(lg, 0));
int num = (n - lg) / 2;
if((n - lg) % 2 != 0) num++;
curr = 0;
int d = 4;
for(int k = 0; k < lg; k++){
int have = 1;
for(int i = lg; i < n; i++){
if(curr == num) curr = 0; have = 1 - have;
v[i][k] = have;
}
num = (n - lg) / d;
if((n - lg) % d != 0) num++;
d *= 2;
}
for(int i = lg; i < n; i++){
string s = "";
for(int j = 0; j < n; j++) s += '0';
s[i] = '1';
add_element(s);
for(int j = 0; j < lg; j++){
if(v[i][j]) s[j] = '1';
if(v[i][j]) add_element(s);
}
}
add_lg(n, lg);
compile_set();
for(int i = 0, i < n; i++) possible.insert(i);
vector<vector<bool>> reconstruct(n, vector<bool>(lg, 0));
vector<int> ind(lg);
vector<int> possible;
vector<bool> possible1(n, 0);
for(int i = 0; i < n; i++){
string s = "";
for(int j = 0; j < n; j++) s += '0';
s[i] = '1';
bool rep = check_element(s);
if(!rep) {possible.push_back(i); possible1[i] = 1;}
}
check_lg(n, lg, possible, ind);
for(int k = 0; k < lg; k++){
for(int i = 0; i < n; i++){
if(possible1[i]) continue;
string s = "";
for(int j = 0; j < n; j++) s += '0';
s[i] = '1';
for(int j = 0; j < k; j++){
if(reconstruct[i][j]) s[ind[j]] = '1';
}
s[ind[k]] = '1';
bool rep = check_element(s);
if(rep) reconstruct[i][k] = 1;
}
}
vector<int> ans(n);
for(int i = 0; i < n; i++){
if(possible1[i]){
for(int j = 0; j < lg; j++){
if(ind[j] == i) ans[i] = j;
}
}else{
for(int j = 0; j < n; j++){
if(reconstruct[i] == v[j]) ans[i] = j;
}
}
}
return ans;
}
/*signed main(){
/*ios_base::sync_with_stdio(0);
cin.tie(0);*/
//freopen("inpt.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
//int tt; cin >> tt;
/*int tt = 1;
for(int t = 1; t <= tt; t++){
//cout << "Case #"<<t << ": ";
solve();
}
}*/
Compilation message
messy.cpp:155:5: warning: "/*" within comment [-Wcomment]
155 | /*ios_base::sync_with_stdio(0);
|
messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:93:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
93 | if(curr == num) curr = 0; have = 1 - have;
| ^~
messy.cpp:93:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
93 | if(curr == num) curr = 0; have = 1 - have;
| ^~~~
messy.cpp:112:21: error: expected ';' before '<' token
112 | for(int i = 0, i < n; i++) possible.insert(i);
| ^~
| ;
messy.cpp:112:22: error: expected primary-expression before '<' token
112 | for(int i = 0, i < n; i++) possible.insert(i);
| ^
messy.cpp:112:32: error: 'possible' was not declared in this scope
112 | for(int i = 0, i < n; i++) possible.insert(i);
| ^~~~~~~~