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;
std::vector<int> restore_permutation(int n, int w, int r) {
vector<int>ans;
for(int i=0;i<n;i++){
ans.push_back(0);
}
queue<pair<int,int>>q;
q.push({0,n-1});
vector<string>cek;
while(!q.empty()){
pair<int,int>ro=q.front();
q.pop();
if((ro.second-ro.first)>=1){
int a=ro.first;
int b=ro.second;
int ti=(a+b)/2;
for(int i=a;i<=ti;i++){
string s="";
for(int j=0;j<a;j++){
s=s+'0';
}
for(int j=a;j<=b;j++){
if(j!=i){
s=s+'1';
}else{
s=s+'0';}
}
for(int j=b+1;j<n;j++){
s=s+'0';
}
// cout<<s<<endl;
add_element(s);
}
q.push({a,ti});
q.push({ti+1,b});
}
}
queue<pair<pair<int,int>,vector<int>>>q1;
vector<int>v;
for(int i=0;i<n;i++){
v.push_back(i);
}
q1.push({{0,n-1},v});
compile_set();
while(!q1.empty()){
pair<pair<int,int>,vector<int>>ro=q1.front();
q1.pop();
int a=ro.first.first;
int b=ro.first.second;
v=ro.second;
if(a==b){
ans[v[0]]=a;
}else{
vector<int>v1;
vector<int>v2;
int ti=(a+b)/2;
int provjera[n];
for(int i=0;i<n;i++){
provjera[i]=0;
}
for(int i=0;i<v.size();i++){
provjera[v[i]]++;
}
for(int i=0;i<n;i++){
if(provjera[i]>0){
string s1="";
for(int j=0;j<n;j++){
if(j==i){
s1=s1+'0';
}else{
if(provjera[j]==1){
s1=s1+'1';
}else{
s1=s1+'0';}
}
}
if(check_element(s1)==true){
v1.push_back(i);
}else{
v2.push_back(i);}
}
}
q1.push({{a,ti},v1});
q1.push({{ti+1,b},v2});
}
}
return ans;
}
/*
int main(){
vector<int>ro=restore_permutation(16,12,12);
}
*/
Compilation message (stderr)
messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=0;i<v.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... |