이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
#include "messy.h"
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
const LL Mod=1000*1000*1000+7;
int n;
int perm[400];
/*add_element("0");
compile_set();
check_element("0");*/
void build(int left,int right)
{
int m=(left+right)/2;
fo(i,left,m)
{
string s="";
for1(j,n)
{
if(j<left || j>right)
s+="1";
if(j==i)
s+="1";
if(j!=i && j>=left && j<=right)
s+="0";
}
add_element(s);
}
if((right-left)==1)
return;
m=(left+right)/2;
build(left,m);
build(m+1,right);
}
void query(vector<int> v,int left,int right)
{
if((right-left)==1)
{
string s="";
for1(j,n)
{
if(j==v[1])
s+="0";
else
s+="1";
}
int t=check_element(s);
if(t==1)
{
perm[v[0]]=left;
perm[v[1]]=right;
}
else
{
perm[v[0]]=right;
perm[v[1]]=left;
}
return;
}
int used[200];
for1(i,n)
used[i]=0;
for0(i,v.size()-1)
used[v[i]]=1;
vector<int> v1;
vector<int> v2;
for0(i,v.size()-1)
{
string s="";
for1(j,n)
{
if(used[j]==0)
s+="1";
if(used[j]==1)
{
if(j==v[i])
s+="1";
else
s+="0";
}
}
int t=check_element(s);
if(t==1)
v1.push_back(v[i]);
else
v2.push_back(v[i]);
}
int m=(left+right)/2;
query(v1,left,m);
query(v2,m+1,right);
}
vector<int> restore_permutation(int n_0, int w, int r) {
n=n_0;
build(1,n);
compile_set();
vector<int> v;
for1(i,n)
v.push_back(i);
query(v,1,n);
vector<int> ANS;
for1(i,n)
ANS.pb(perm[i]-1);
return ANS;
}
# | 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... |