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 "messy.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
map<string,int> scuza;
int ask(string&s) {
if (scuza[s]) return scuza[s]-1;
int x=check_element(s);
scuza[s]=x+1;
return x;
}
void rec(int l, int r, string&s) {
if (r-l==1) return;
int m=(l+r)>>1;
for (int i=l; i<m; ++i) {
s[i]='1';
add_element(s);
s[i]='0';
}
for(int i=m;i<r;++i) {
s[i]='1';
}
rec(l,m,s);
for(int i=l;i<m;++i) {
s[i]='1';
}
for(int i=m;i<r;++i) {
s[i]='0';
}
rec(m,r,s);
for(int i=l;i<m;++i) {
s[i]='0';
}
}
vector<int> ans;
int N;
void rec(int l, int r, vector<int>&v) {
string z(N,'0');
for(auto&x:v) z[x]='1';
if (r-l==1) {
forn(i,N) if (z[i]=='0') {
ans[i]=l;
return;
}
}
int m=(l+r)>>1;
vector<int> f,s;
//cout<<l<<' '<<r<<' '<<z<<'\n';
forn(j,N) {
if (z[j]=='1') continue;
z[j]='1';
int x=ask(z);
z[j]='0';
if (x) f.push_back(j);
else s.push_back(j);
}
for(auto&x:s) v.push_back(x);
rec(l,m,v);
for(auto&x:s) v.pop_back();
for(auto&x:f) v.push_back(x);
rec(m,r,v);
for(auto&x:f) v.pop_back();
}
vector<int> restore_permutation(int n, int w, int r) {
string z(n,'0');
rec(0,n,z);
ans.assign(n,-1); N=n;
compile_set();
vector<int> v;
rec(0,n,v);
return ans;
}
Compilation message (stderr)
messy.cpp: In function 'void rec(int, int, std::vector<int>&)':
messy.cpp:61:14: warning: unused variable 'x' [-Wunused-variable]
61 | for(auto&x:s) v.pop_back();
| ^
messy.cpp:64:14: warning: unused variable 'x' [-Wunused-variable]
64 | for(auto&x:f) v.pop_back();
| ^
# | 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... |