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 "messy.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX_N = 128;
int n;
int ans[MAX_N];
void solve(int l, int r, vector<int> lcand, vector<int> rcand) {
if (l+1 == r) {
ans[l] = lcand[0];
ans[r] = rcand[0];
return;
}
int m = (l+r)/2;
vector<int> nxt_lcand, nxt_rcand;
string query;
for (int i=0; i<n; ++i) query.push_back('0');
for (int idx: rcand) query[idx] = '1';
for (int idx: lcand) {
query[idx] = '1';
// cout << query << endl;
bool ret = check_element(query);
(ret ? nxt_lcand : nxt_rcand).push_back(idx);
query[idx] = '0';
}
solve(l, m, nxt_lcand, nxt_rcand);
query.clear();
nxt_lcand.clear();
nxt_rcand.clear();
for (int i=0; i<n; ++i) query.push_back('0');
for (int idx: lcand) query[idx] = '1';
for (int idx: rcand) {
query[idx] = '1';
// cout << query << endl;
bool ret = check_element(query);
(ret ? nxt_lcand : nxt_rcand).push_back(idx);
query[idx] = '0';
}
solve(m+1, r, nxt_lcand, nxt_rcand);
}
void compile(int l, int r) {
if (l+1 == r) return;
int m = (l+r)/2;
compile(l, m);
compile(m+1, r);
string query;
for (int i=0; i<n; ++i) query.push_back('0');
for (int i=m+1; i<=r; ++i) query[i] = '1';
for (int i=l; i<=(l+m)/2; ++i) {
query[i] = '1';
// cout << query << endl;
add_element(query);
query[i] = '0';
}
query.clear();
for (int i=0; i<n; ++i) query.push_back('0');
for (int i=l; i<=m; ++i) query[i] = '1';
for (int i=m+1; i<=(m+1+r)/2; ++i) {
query[i] = '1';
// cout << query << endl;
add_element(query);
query[i] = '0';
}
}
vector<int> restore_permutation(int N, int w, int r) {
n = N;
string query;
for (int i=0; i<n; ++i) query.push_back('0');
for (int i=0; i<n/2; ++i) {
query[i] = '1';
// cout << query << '\n';
add_element(query);
query[i] = '0';
}
compile(0, n-1);
compile_set();
// cout << "mid" << endl;
vector<int> lcand, rcand;
for (int i=0; i<n; ++i) {
query[i] = '1';
bool ret = check_element(query);
(ret ? lcand : rcand).push_back(i);
query[i] = '0';
}
solve(0, n-1, lcand, rcand);
vector<int> ret(n);
for (int i=0; i<n; ++i) ret[ans[i]] = i;
return ret;
}
# | 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... |