이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<" = "<<x<<endl
struct parent
{
int p,edge;
};
vector<int> Exits[1000006];
vector<int> X;
vector<int> Y;
map<int,parent> memo;
int NEXT_FREE_INDEX=1;
void createTree(int root,int i,int lv,int limit,int sum,int unused)
{
if(lv==limit-1){ //Last level of switches
if(unused==1)
X.push_back(-root);
else{
X.push_back(sum);
parent x={i,0};
memo[sum]=x;
}
sum+=(1<<lv);
parent x={i,1};
Y.push_back(sum);
memo[sum]=x;
}
else{
int child_size=(1<<(limit-lv-1));
if(unused>=child_size){ //Drop left child
X.push_back(-root);
Y.push_back(-NEXT_FREE_INDEX);
NEXT_FREE_INDEX++;
createTree(root,NEXT_FREE_INDEX-1,lv+1,limit,sum+(1<<lv),unused-child_size);
}
else{
X.push_back(-NEXT_FREE_INDEX);
NEXT_FREE_INDEX++;
Y.push_back(0);
createTree(root,NEXT_FREE_INDEX-1,lv+1,limit,sum,unused);
Y[i-1]=-NEXT_FREE_INDEX;
NEXT_FREE_INDEX++;
createTree(root,NEXT_FREE_INDEX-1,lv+1,limit,sum+(1<<lv),0);
}
}
}
int logn[200005];
void create_circuit(int m, vector<int> A) {
for(int i=2;i<=200000;i++){
logn[i]=logn[(i+1)/2]+1;
}
A.push_back(0);
int n=A.size();
vector<int> C(m+1);
for(int i=0;i<=m;i++){
C[i]=-1;
}
int LOG=logn[n];
NEXT_FREE_INDEX++;
createTree(1,1,0,LOG,0,(1<<LOG)-n);
/*for(int i=0;i<n;i++){
cout<<X[i]<<" "<<Y[i]<<endl;
}*/
int j=0;
for(auto x: memo){
int p=x.second.p;
int edge=x.second.edge;
if(edge==0) X[p-1]=A[j];
else Y[p-1]=A[j];
j++;
}
/*for(int i=0;i<n;i++){
cout<<X[i]<<" "<<Y[i]<<endl;
}*/
answer(C, X, Y);
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |