이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include <bits/stdc++.h>
#define MAXN (1<<20)
#define MAXM 200010
#define PRINT(x) cerr<<#x<<' '<<x<<endl;
#define mid (l+r)/2
#define pb push_back
using namespace std;
vector<int> X, Y, C;
int x[MAXN], y[MAXN], stdva, idxx[MAXN];
int N, idx;
set<int> nodes;
void ubaci(int node, int put, int kraj, int dub) {
if(dub == stdva) {
if(put == 0) x[node] = kraj;
if(put == 1) y[node] = kraj;
return;
}
if(!(put&1)) {
if(x[node] == -1) x[node] = --idx;
ubaci(-x[node], put>>1, kraj, dub+1);
} else {
if(y[node] == -1) y[node] = --idx;
ubaci(-y[node], put>>1, kraj, dub+1);
}
}
void nadji(int put, int kraj, int l, int r) {
if(l == r) {
idxx[l] = kraj;
return;
}
if(!(put&1)) nadji(put>>1, kraj, l, mid);
else nadji(put>>1, kraj, mid+1, r);
}
void create_circuit(int M, std::vector<int> A) {
N = A.size();
C.resize(M+1);
for(int i = 1; i <= M; i++) C[i] = -1;
C[0] = -1;
idx = -1;
for(int i = 0; i < 20; i++) {
if((1<<i) > N) {
stdva = i;
break;
}
}
for(int i = 0; i < (1<<stdva); i++) {
nadji(i, i, 0, (1<<stdva)-1);
}
for(int i = 0; i < (1<<(stdva-1)); i++) {
nodes.insert(idxx[i]);
}
nodes.insert(idxx[(1<<(stdva))-1]);
int xx = N-(1<<(stdva-1));
int yy = (1<<stdva)-xx;
for(int i = (1<<(stdva))-2; i > yy; i--) {
nodes.insert(idxx[i]);
}
fill(x, x+MAXN, -1);
fill(y, y+MAXN, -1);
int ii = 0;
for(auto x : nodes) {
ubaci(1, x, A[ii], 1);
ii++;
}
idx = -idx;
X.resize(idx);
Y.resize(idx);
for(int i = 1; i <= idx; i++) {
X[i-1] = x[i];
Y[i-1] = y[i];
}
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... |