#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int m,n;
std::vector<int> C;
int num;
vector <int> X,Y;
int times[400004];
const int inf = 1e7;
void solve(int v, int from, int to)
{
// cout<<v<<" "<<from<<" "<<to<<endl;
X.push_back(-1);
Y.push_back(-1);
int mid = (from+to)/2;
if(from<mid&&from<n)
{
num++;
Y[v]=-num-1;
solve(num,from,mid);
}
else
{
if(n<=from)Y[v] = inf;
else
Y[v]=-1;
}
if(mid+1<to&&mid+1<n)
{
num++;
X[v]=-num-1;
solve(num,mid+1,to);
}
else
{if(n<=mid+1)X[v] = inf;
else
X[v]=-1;
}
return ;
}
void create_circuit(int _M, std::vector<int> _A) {
a = _A;
a.push_back(0);
n = a.size();
m = _M;
C.resize(m+1);
C[0] = -1;
for (int i = 1; i <= m; ++i) {
C[i] = -1;
}
int br = 1;
while(br<n)br*=2;
solve(0, 0, br-1);
int c = 0;
int x = 0;
while(c<n)
{
times[x]++;
if(times[x]%2==1)
{
if(X[x]==-1)
{
X[x] = a[c];
c++;
x = 0;
}
else
{
x = -X[x]-1;
}
}
else
{
if(Y[x]==-1)
{
Y[x] = a[c];
c++;
x = 0;
}
else
{
x = -Y[x]-1;
}
}
if(x==-inf-1)x=0;
} //for(int i=0;i<=num;i++)
/// {
///cout<<i<<": "<<X[i]<<" "<<Y[i]<<endl;
//}
for(int i=0;i<=num;i++)
{
if(X[i]==inf)X[i] = -1;
if(Y[i]==inf)Y[i]=-1;
}
//cout<<"YEs"<<endl;
answer(C, X, Y);
}
/*#include <bits/stdc++.h>
using namespace std;
void answer(vector<int> C, vector<int> X, vector<int> Y);
vector<int> C, X, Y;
const int _N = 1e6 + 7;
int B[_N][2], timer[_N], cnt, n, m, k = 0;
int f(int s, int e){
if(n <= s){
return 1;
}
if(s == e){
return -1;
}
int m = (s + e) / 2, c = ++k;
B[c][1] = f(s, m);
B[c][0] = f(m + 1, e);
return c;
}
void create_circuit(int M, vector<int> A){
for(int i = 0; i < M; i++){
C.push_back(-1);
}
C.push_back(-1);
A.push_back(0);
n = (int)A.size();
m = M;
int t = 1;
while(t < n){
t *= 2;
}
f(0, t - 1);
for(int i = 1, c = 0; c < n;){
int &x = B[i][timer[i] & 1];
++timer[i];
if(x < 0){
x = -A[c++];
i = 1;
continue;
}
i = x;
}
for(int i = 1; i <= k; i++){
X.push_back(-B[i][0]);
Y.push_back(-B[i][1]);
}
for(int i=0;i<X.size();i++)
{
cout<<i<<": "<<X[i]<<" "<<Y[i]<<endl;
}
answer(C, X, Y);
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
47 ms |
5212 KB |
Output is correct |
3 |
Correct |
44 ms |
5084 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1472 KB |
Output is correct |
6 |
Correct |
67 ms |
7392 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
47 ms |
5212 KB |
Output is correct |
3 |
Correct |
44 ms |
5084 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1472 KB |
Output is correct |
6 |
Correct |
67 ms |
7392 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
89 ms |
8424 KB |
Output is correct |
9 |
Correct |
94 ms |
8948 KB |
Output is correct |
10 |
Correct |
137 ms |
12928 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
47 ms |
5212 KB |
Output is correct |
3 |
Correct |
44 ms |
5084 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1472 KB |
Output is correct |
6 |
Correct |
67 ms |
7392 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
89 ms |
8424 KB |
Output is correct |
9 |
Correct |
94 ms |
8948 KB |
Output is correct |
10 |
Correct |
137 ms |
12928 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
134 ms |
12376 KB |
Output is correct |
15 |
Correct |
88 ms |
7904 KB |
Output is correct |
16 |
Correct |
130 ms |
12196 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
136 ms |
12564 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
216 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
85 ms |
6944 KB |
Output is correct |
3 |
Correct |
81 ms |
7008 KB |
Output is correct |
4 |
Correct |
121 ms |
10596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
85 ms |
6944 KB |
Output is correct |
3 |
Correct |
81 ms |
7008 KB |
Output is correct |
4 |
Correct |
121 ms |
10596 KB |
Output is correct |
5 |
Correct |
137 ms |
11984 KB |
Output is correct |
6 |
Correct |
136 ms |
11616 KB |
Output is correct |
7 |
Correct |
150 ms |
11772 KB |
Output is correct |
8 |
Correct |
126 ms |
11428 KB |
Output is correct |
9 |
Correct |
80 ms |
7148 KB |
Output is correct |
10 |
Correct |
131 ms |
11436 KB |
Output is correct |
11 |
Correct |
124 ms |
11028 KB |
Output is correct |
12 |
Correct |
81 ms |
7272 KB |
Output is correct |
13 |
Correct |
84 ms |
7652 KB |
Output is correct |
14 |
Correct |
84 ms |
7732 KB |
Output is correct |
15 |
Correct |
85 ms |
7868 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
75 ms |
7612 KB |
Output is correct |
18 |
Correct |
90 ms |
7260 KB |
Output is correct |
19 |
Correct |
85 ms |
7224 KB |
Output is correct |
20 |
Correct |
133 ms |
11264 KB |
Output is correct |
21 |
Correct |
132 ms |
11028 KB |
Output is correct |
22 |
Correct |
123 ms |
11024 KB |
Output is correct |