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<bits/stdc++.h>
#include<messy.h>
using namespace std;
int N, W, R, tot, tot2;
int perm[202];
set<string> test, tru;
/*
// to be removed when submitting
void add_element(string s)
{
++tot;
test.insert(s);
}
bool check_element(string s)
{
++tot2;
if(tru.find(s) != tru.end())
return 1;
return 0;
}
void compile_set()
{
string ans;
for(int i = 0; i < N; ++i)
ans += '0';
for(set<string> ::iterator it = test.begin(); it != test.end(); ++it)
{
string ss = *it;
for(int i = 0; i < N; ++i)
ans[i] = '0';
for(int i = 0; i < N; ++i)
ans[perm[i]] = ss[i];
tru.insert(ans);
}
}
*/
int poz[202];
vector<int> pospoz[202][202];
void build(int st, int dr)
{
if(st == dr)
return;
string s;
for(int i = 0; i < N; ++i)
s += '1';
int mid = (st + dr) / 2;
for(int i = st; i <= dr; ++i)
s[i] = '0';
for(int i = st; i <= mid; ++i)
{
s[i] = '1';
--W;
if(W < 0)
while(1);
add_element(s);
s[i] = '0';
}
build(st, mid);
build(mid+1, dr);
}
void restore(int st, int dr)
{
if(st == dr)
{
poz[st] = pospoz[st][st][0];
return;
}
string twice;
for(int i = 0; i < N; ++i)
twice += '1';
for(int i = 0; i < pospoz[st][dr].size(); ++i)
twice[pospoz[st][dr][i]] = '0';
int mid = (st + dr) / 2;
for(int i = 0; i < pospoz[st][dr].size(); ++i)
{
int pp = pospoz[st][dr][i];
twice[pp] = '1';
--R;
if(R < 0)
while(1);
bool xxx = check_element(twice);
if(xxx)
pospoz[st][mid].push_back(pp);
else
pospoz[mid+1][dr].push_back(pp);
twice[pp] = '0';
}
restore(st, mid);
restore(mid+1, dr);
}
vector<int> restore_permutation(int n, int w, int r)
{
N = n;
W = w;
R = r;
build(0, n-1);
compile_set();
for(int i = 0; i < n; ++i)
pospoz[0][n-1].push_back(i);
if(n == 8)
restore(0, n-1);
vector<int> ans;
for(int i = 0; i < n; ++i)
ans.push_back(poz[i]);
return ans;
}
Compilation message (stderr)
messy.cpp: In function 'void restore(int, int)':
messy.cpp:73:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < pospoz[st][dr].size(); ++i)
~~^~~~~~~~~~~~~~~~~~~~~~~
messy.cpp:76:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < pospoz[st][dr].size(); ++i)
~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |