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;
#define pb(x) push_back(x)
vector<int> ans;
int n;
void put(int l , int r){
if(l == r - 1)return;
int m = (l + r)/2;
string s = "";
for(int i = 0; i < n; i++){
s += '1';
}
for(int i = l; i < r; i++){
s[i] = '0';
}
for(int i = l; i < m; i++){
s[i] = '1';
//cout << s << '\n';
add_element(s);
s[i] = '0';
}
add_element(s);
put(l , m);
put(m , r);
}
void solve(vector<int>& v , int l , int r){
//cout << l << ' ' << r << ' ' << v.size() << endl;
if(l == r - 1){
ans[v[0]] = l;
return;
}
int m = (l + r)/2;
string s = "";
for(int i = 0; i < n; i++)s += '1';
//for(int i = l; i < r; i++)s[i] = '0';
for(int i = 0; i < v.size(); i++){
s[v[i]] = '0';
}
vector<int> a , b;
for(int i = 0; i < v.size(); i++){
s[v[i]] = '1';
//cout << s << ' ' << check_element(s) << '\n';
if(check_element(s)){
//cout << v[i] << ' ';
a.pb(v[i]);
}
else b.pb(v[i]);
s[v[i]] = '0';
}
//cout << '\n';
//assert(a.size() == b.size());
solve(a , l , m);
solve(b,m,r);
}
vector<int> restore_permutation(int nn, int w, int r){
n = nn;
ans.resize(n);
put(0 , n);
compile_set();
vector<int> cur;
for(int i = 0; i < n; i++){
cur.pb(i);
}
solve(cur , 0 , n);
//cout << "came" << endl;
/*for(int i = 0; i < n; i++){
cout << ans[i] << endl;
}*/
return ans;
}
Compilation message (stderr)
messy.cpp: In function 'void solve(std::vector<int>&, int, int)':
messy.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
messy.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | 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... |