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 ll long long
using namespace std;
int N,niz[130],stepen[10],gde[130];
bool locked[130];
string ps;
vector<int> ret,poz,broj[130],tren;
void add(){
stepen[0]=1;
for(int i=1;i<=7;i++)
stepen[i]=stepen[i-1]*2;
ps="";
for(int i=1;i<=N;i++)
ps.push_back('1');
for(int i=1;i<=7;i++){
ps[i-1]='0';
add_element(ps);
}
for(int i=0;i<N;i++)
niz[i]=i;
for(int it=0;stepen[it]<N;it++){
for(int i=0;i<ps.size();i++)
ps[i]='0';
for(int i=0;i<it;i++)
ps[i]='1';
for(int i=it;i<N;i++)
if(i&stepen[it]){
ps[i]='1';
add_element(ps);
ps[i]='0';
}
}
return;
}
bool pitaj(){
string a=ps;
return check_element(a);
}
void read(){
ret.resize(N);
for(int it=0;stepen[it]<N;it++){
///Trazi gde je it-1
if(it!=0){
int traz=0;
for(int j=0;j<it;j++)
if((it-1)&stepen[j])
traz+=stepen[j];
for(int i=0;i<N;i++)
ps[i]='1';
for(int i=0;i<poz.size();i++)
ps[poz[i]]='0';
for(int i=0;i<N;i++){
if(locked[i])
continue;
if(gde[i]!=traz)
continue;
ps[i]='0';
if(check_element(ps)){
locked[i]=true;
gde[i]=it-1;
poz.push_back(i);
//cout<<it-1<<" je na poziciji "<<i<<endl;
break;
}
else
ps[i]='1';
}
}
for(int i=0;i<N;i++)
ps[i]='0';
for(int i=0;i<poz.size();i++)
ps[poz[i]]='1';
for(int i=0;i<stepen[it];i++)
broj[i].clear();
for(int i=0;i<N;i++){
int br=gde[i]&(stepen[it]-1);
//cout<<i<<" "<<br<<" "<<stepen[it]<<endl;
broj[br].push_back(i);
}
for(int tb=0;tb<stepen[it];tb++){
tren=broj[tb];
// cout<<"TREN SIZE: "<<tren.size()<<endl;
for(int i=0;i<tren.size();i++)
if(!locked[tren[i]]){
swap(tren[i],tren[tren.size()-1]);
break;
}
int pi,uk=0;
for(int i=0;i<tren.size()-1;i++){
if(uk==tren.size()/2)
break;
pi=i;
int koji=tren[i];
if(locked[koji]){
// cout<<"LOKOVAN "<<koji<<endl;
if(gde[koji]&stepen[it])
uk++;
continue;
}
ps[koji]='1';
if(pitaj()){
// cout<<"IMA"<<endl;
gde[koji]+=stepen[it];
uk++;
}
ps[koji]='0';
}
//cout<<uk<<endl;
if(uk!=tren.size()/2){
// cout<<"OVDE "<<pi<<endl;
// cout<<tren[1]<<" "<<locked[tren[1]]<<endl;
for(int i=pi+1;i<tren.size();i++)
if(!locked[tren[i]])
gde[tren[i]]+=stepen[it];
}
}
/* cout<<stepen[it]<<" ZAVRSEN: ";
for(int i=0;i<N;i++)
cout<<gde[i]<<" ";
cout<<endl;*/
}
for(int i=0;i<N;i++)
ret[i]=gde[i];
}
vector<int> restore_permutation(int n, int w, int r) {
N=n;
add();
compile_set();
read();
return ret;
}
Compilation message (stderr)
messy.cpp: In function 'void add()':
messy.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<ps.size();i++)
| ~^~~~~~~~~~
messy.cpp: In function 'void read()':
messy.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=0;i<poz.size();i++)
| ~^~~~~~~~~~~
messy.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i=0;i<poz.size();i++)
| ~^~~~~~~~~~~
messy.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i=0;i<tren.size();i++)
| ~^~~~~~~~~~~~
messy.cpp:91:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(int i=0;i<tren.size()-1;i++){
| ~^~~~~~~~~~~~~~
messy.cpp:92:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | if(uk==tren.size()/2)
| ~~^~~~~~~~~~~~~~~
messy.cpp:111:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | if(uk!=tren.size()/2){
| ~~^~~~~~~~~~~~~~~
messy.cpp:114:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | for(int i=pi+1;i<tren.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... |