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)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
int N;
void encode(vector<int> s, vector<int> t) {
if (s.size()==1) return;
vector<int> s1,s2;
int n=s.size();
forn(i,n/2) s1.pb(s[i]), s2.pb(s[i+n/2]);
string q(N,'0');
for(auto&x:t) q[x]='1';
for(auto&x:s1) {
q[x]='1';
add_element(q);
q[x]='0';
}
for(auto&x:s2) t.pb(x);
encode(s1,t);
for(auto&x:s2) t.pop_back();
for(auto&x:s1) t.push_back(x);
encode(s2,t);
}
int ans[128];
void decode(vector<int> s, vector<int> t, int l, int r) {
if (r-l==1) {
ans[s[0]]=l;
return;
}
int m=(l+r)>>1;
vector<int> s1, s2;
string q(N,'0');
for(auto&x:t) q[x]='1';
for(auto&x:s) {
q[x]='1';
int z=check_element(q);
if (z) s1.pb(x);
else s2.pb(x);
q[x]='0';
}
for(auto&x:s2) t.pb(x);
decode(s1,t,l,m);
for(auto&x:s2) t.pop_back();
for(auto&x:s1) t.push_back(x);
decode(s2,t,m,r);
}
vector<int> restore_permutation(int n, int w, int r) {
N=n;
vector<int> s,t;
forn(i,n) s.pb(i);
encode(s,t);
compile_set();
decode(s,t,0,n);
vector<int> z(n);
forn(i,n) z[i]=ans[i];
return z;
}
Compilation message (stderr)
messy.cpp: In function 'void encode(std::vector<int>, std::vector<int>)':
messy.cpp:26:14: warning: unused variable 'x' [-Wunused-variable]
26 | for(auto&x:s2) t.pop_back();
| ^
messy.cpp: In function 'void decode(std::vector<int>, std::vector<int>, int, int)':
messy.cpp:50:14: warning: unused variable 'x' [-Wunused-variable]
50 | for(auto&x:s2) t.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... |