#include "doll.h"
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
vector<vector<int>> adj;
vector<int> C, X, Y;
int cnt = -1;
void build(int x) {
int n = adj[x].size();
if (n == 1) C[x] = adj[x][0];
else if (n) {
C[x] = cnt; cnt--;
for (int i = n - 1; i > 0; i--) {
Y.pb(0);
int first = cnt + 1;
int time = i - 1;
pair<int,int> act = {0, 0}, pre = {1, cnt + 1};
while (time) {
if (time % pre.fi == 0) {
time -= pre.fi;
Y.pb(pre.se);
X.pb(cnt);
act = {pre.fi, cnt};
pre.fi *= 2;
cnt--;
}
else {
time -= act.fi;
Y.pb(act.se);
X.pb(cnt);
pre = {act.fi * 2, act.se};
act.se = cnt;
cnt--;
}
}
X.pb(adj[x][n - 1 - i]);
auto it = Y.end() + (cnt - first);
if (i != 1) {
*it = cnt;
cnt--;
}
else *it = adj[x].back();
}
}
else {
C[x] = 0;
}
}
void create_circuit(int M, vector<int> A) {
if (M == 1) {
int N = A.size();
A.push_back(0);
vector<int> C(M + 1, INT_MAX), X, Y;
C[0] = A[0];
int time = N - 1;
vector<pair<int,int>> fact = {{1, 1}};
int cnt = -1;
while (time) {
int next = 0;
for (auto x : fact) {
if (time % x.first == 0) {
time -= x.first;
next = x.first;
X.push_back(x.second);
if (cnt != -1) Y.push_back(cnt);
else C[1] = cnt;
cnt--;
break;
}
}
for (auto &x : fact) x.first += next;
fact.push_back({next, cnt + 1});
}
if (cnt != -1) Y.push_back(0);
else C[1] = 0;
answer(C, X, Y);
return;
}
int N = A.size();
A.push_back(0);
C.resize(M + 1);
adj.resize(M + 1);
adj[0].pb(A[0]); C[0] = A[0];
for (int i = 1; i <= N; i++) adj[A[i-1]].pb(A[i]);
for (int i = 1; i <= M; i++) build(i);
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
6756 KB |
Output is correct |
3 |
Correct |
14 ms |
5720 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
3928 KB |
Output is correct |
6 |
Correct |
22 ms |
8516 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
6756 KB |
Output is correct |
3 |
Correct |
14 ms |
5720 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
3928 KB |
Output is correct |
6 |
Correct |
22 ms |
8516 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
28 ms |
9032 KB |
Output is correct |
9 |
Correct |
30 ms |
10244 KB |
Output is correct |
10 |
Correct |
48 ms |
13924 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
16 ms |
6756 KB |
Output is correct |
3 |
Correct |
14 ms |
5720 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
3928 KB |
Output is correct |
6 |
Correct |
22 ms |
8516 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
28 ms |
9032 KB |
Output is correct |
9 |
Correct |
30 ms |
10244 KB |
Output is correct |
10 |
Correct |
48 ms |
13924 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
51 ms |
14828 KB |
Output is correct |
15 |
Incorrect |
43 ms |
10024 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
10 ms |
2908 KB |
Output is correct |
3 |
Correct |
10 ms |
2908 KB |
Output is correct |
4 |
Correct |
15 ms |
4160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
10 ms |
2908 KB |
Output is correct |
3 |
Correct |
10 ms |
2908 KB |
Output is correct |
4 |
Correct |
15 ms |
4160 KB |
Output is correct |
5 |
Partially correct |
72 ms |
18860 KB |
Output is partially correct |
6 |
Incorrect |
109 ms |
24436 KB |
over 400000 switches |
7 |
Halted |
0 ms |
0 KB |
- |