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"
#define DIM 300
using namespace std;
string a[DIM];
int k,n,w,r,pas;
int p[DIM],v[DIM];
vector <int> sol;
/*void add_element(string s){
a[++k] = s;
}
void compile_set(){
for (int i=1;i<=k;i++){
string s = "";
for (int j=0;j<n;j++)
s += a[i][p[j]];
a[i] = s;
}
}
int check_element(string s){
pas++;
for (int i=1;i<=k;i++)
if (a[i] == s)
return 1;
return 0;
}*/
void add (int st, int dr){
if (st == dr)
return;
int mid = (st+dr)>>1;
string s = "";
for (int i=0;i<n;i++){
if (i < st || i > dr)
s += "1";
else s += "0";
}
for (int i=st;i<=mid;i++){
s[i] = '1';
add_element(s);
s[i] = '0';
}
add (st,mid);
add (mid+1,dr);
}
void solve (string s, int st, int dr){
if (st == dr){
for (int i=0;i<n;i++){
if (s[i] == '0'){
sol[i] = st;
break;
}}
return;
}
int mid = (st+dr)>>1;
vector <int> poz,poz2;
for (int i=0;i<=n-1;i++){
if (s[i] == '1')
continue;
s[i] = '1';
if (check_element(s) == 0)
poz.push_back(i);
else poz2.push_back(i);
s[i] = '0';
}
for (auto it : poz)
s[it] = '1';
solve (s,st,mid);
for (auto it : poz)
s[it] = '0';
for (auto it : poz2)
s[it] = '1';
solve (s,mid+1,dr);
}
vector<int> restore_permutation (int N, int w, int r){
int i;
n = N;
add (0,n-1);
compile_set();
string s = "";
for (i=0;i<n;i++){
sol.push_back(0);
s += "0";
}
solve (s,0,n-1);
return sol;
}
# | 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... |