이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "messy.h"
#include <string>
#include <vector>
using namespace std;
int N;
vector<int> p_inv; //p[ p_inv[i] ] = i
void find_p_inv(int a, int b, vector<int> goodcells)
//goodcells contains all the elements i with a <= p_inv[i] <= b
{
if(a == b)
{
p_inv[goodcells[0]] = a;
return;
}
string base_query(N, '1');
for(int g: goodcells)
base_query[g] = '0';
vector<int> goodcells_1, goodcells_2;
for(int g: goodcells)
{
string query = base_query;
query[g] = '1';
if(check_element(query))
goodcells_1.push_back(g);
else
goodcells_2.push_back(g);
}
find_p_inv(a, (a+b)/2, goodcells_1);
find_p_inv((a+b)/2+1, b, goodcells_2);
}
vector<int> restore_permutation(int n, int w, int r)
{
N = n;
p_inv = vector<int>(n, 0);
for(int g = n; g >= 2; g /= 2) //size of gap
{
for(int i = 0; i < n; i += g) //starting point of gap
{
for(int o = 0; o < g/2; o++)
{
string s(n, '1');
for(int j = i; j < i+g; j++)
if(j-i != o)
s[j] = '0';
add_element(s);
}
}
}
compile_set();
// cerr << n << '\n';
vector<int> goodcells;
for(int i = 0; i < n; i++) goodcells.push_back(i);
find_p_inv(0, n-1, goodcells);
// vector<int> p(n);
// for(int i = 0; i < n; i++)
// p[p_inv[i]] = i;
return p_inv;
}
# | 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... |