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>
using namespace std;
int n;
vector<int> p;
vector<set<int>> inside;
#ifndef _DEBUG
#include "messy.h"
#endif
#ifdef _DEBUG
void add_element(string s)
{
cout << s << "\n";
}
bool check_element(string s)
{
cout << s << "\n";
bool b;
cin >> b;
return b;
}
void compile_set()
{
cout << "-------------------\n";
}
#endif
void segAdd(int l, int r, int i)
{
if (l + 1 == r)
return;
int m = l + (r - l) / 2;
string s(n, '0');
for (int i = 0; i < n; i++)
s[i] = ((i >= l && i < r) ? '0' : '1');
for (int i = l; i < m; i++)
{
string out = s;
out[i] = '1';
add_element(out);
}
segAdd(l, m, i * 2 + 1);
segAdd(m, r, i * 2 + 2);
}
void segGet(int l, int r, int i)
{
if (l + 1 == r)
{
p[*(inside[i].begin())] = l;
return;
}
string s(n, '0');
for (int j = 0; j < n; j++)
if (!inside[i].count(j))
s[j] = '1';
for (int val : inside[i])
{
string query = s;
query[val] = '1';
if (check_element(query))
inside[i * 2 + 1].insert(val);
else
inside[i * 2 + 2].insert(val);
}
int m = l + (r - l) / 2;
segGet(l, m, i * 2 + 1);
segGet(m, r, i * 2 + 2);
}
vector<int> restore_permutation(int N, int w, int r)
{
n = N;
p = vector<int>(n);
segAdd(0, n, 0);
inside = vector<set<int>>(n * 4);
for (int i = 0; i < n; i++)
inside[0].insert(i);
compile_set();
segGet(0, n, 0);
return p;
}
#ifdef _DEBUG
int main()
{
int n, w, r;
cin >> n >> w >> r;
auto blub = restore_permutation(n, w, r);
for (int x : blub)
cout << x << " ";
}
#endif
# | 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... |