이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 4e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int N;
vector<int> ans, S_x, S_y, state;
int create(int qnt) {
if(qnt == 1) return 1;
int a = create(qnt/2), b = create(qnt/2);
S_x.pb(a);
S_y.pb(b);
//cout << "creating: " << qnt << "\nreturn: " << -sz(S_y) << "\n";
return -sz(S_y);
}
void dfs(int x, int qtd) {
if(qtd == N) return;
//cout << x << " " << qtd << " " << state[-x-1] << "\n";
if(state[-x-1] == 0) {
state[-x-1] = 1;
if(S_x[-x-1] == 1) S_x[-x-1] = qtd, dfs(-sz(S_x), qtd+1);
else dfs(S_x[-x-1], qtd);
}
else {
state[-x-1] = 0;
if(S_y[-x-1] == 1) S_y[-x-1] = qtd, dfs(-sz(S_x), qtd+1);
else dfs(S_y[-x-1], qtd);
}
}
void create_circuit(int M, vector<int> A) {
A.pb(0);
N = sz(A);
vector<int> pot;
for(int i = 20; i >= 0; i--)
if(N >= (1<<i)) pot.pb(i), N -= (1<<i);
N = sz(A);
reverse(all(pot));
for(int i = 0, last = 0; i < sz(pot); i++) {
int k = create((1<<pot[i]));
if(i > 0) {
S_x.pb(k);
S_y.pb(last);
}
if(i == sz(pot)-1) break;
int add = pot[i+1] - pot[i] - !!i;
while(add--) {
S_y.pb(k);
S_x.pb(-sz(S_y));
k = -sz(S_x);
}
last = -sz(S_x);
}
int S = sz(S_x);
ans.resize(M+1, -S);
state.resize(S);
for(int i = 0; i < S; i++)
if(S_x[i] == -i-1) S_x[i] = -S;
// for(int i = 0; i < S; i++)
// cout << S_x[i] << " " << S_y[i] << endl;
dfs(-S, 0);
for(int i = 0; i < S; i++) {
if(S_x[i] >= 0) S_x[i] = A[S_x[i]];
if(S_y[i] >= 0) S_y[i] = A[S_y[i]];
}
return answer(ans, S_x, S_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... |