#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
const int MAX_M = 1e5 + 5;
const int INF = 1e9 + 7;
int N, M, S;
set <int> keepnxt[MAX_M];
vector <int> nxt[MAX_M];
vector<int> C, X, Y;
vector <int> leaf;
vector <int> pattern[20];
void build(int u, int d) {
if(d == 0) {
return;
}
X[u - 1] = -(++S);
if(d == 1) {
leaf.push_back(S - 1);
}
build(S, d - 1);
Y[u - 1] = -(++S);
if(d == 1) {
leaf.push_back(S - 1);
}
build(S, d - 1);
}
void create_circuit(int m, vector <int> A) {
N = A.size(), M = m;
C.resize(M + 1);
X.resize(1e6, INF);
Y.resize(1e6, INF);
pattern[0].push_back(0);
for(int j = 1; j < 20; j++) {
pattern[j].resize(pattern[j - 1].size() * 2);
for(int i = 0; i < pattern[j - 1].size(); i++) {
pattern[j][i * 2] = pattern[j - 1][i];
}
for(int i = 0; i < pattern[j].size(); i += 2) {
pattern[j][i + 1] = pattern[j][i] + (1<<(j - 1));
}
}
A.push_back(0);
for(int i = 0; i < N; i++) {
if(keepnxt[A[i]].count(A[i + 1])) {
continue;
}
if(A[i] != A[i + 1]) {
keepnxt[A[i]].insert(A[i + 1]);
}
nxt[A[i]].push_back(A[i + 1]);
}
C[0] = A[0];
for(int a = 1; a <= M; a++) {
if(nxt[a].empty()) {
continue;
}
else if(nxt[a].size() == 1) {
C[a] = nxt[a][0];
}
else {
leaf.clear();
int root = ++S;
C[a] = -S;
int numberofLevel = ceil(1.0 * log2(nxt[a].size()));
build(S, numberofLevel - 1);
if(numberofLevel == 1) {
leaf.push_back(root - 1);
}
for(int i = 0; i < (1<<numberofLevel); i += 2) {
int idx = pattern[numberofLevel][i];
if(idx + 1 >= nxt[a].size()) {
X[leaf[i / 2]] = -root;
}
else {
X[leaf[i / 2]] = nxt[a][idx];
}
}
for(int i = 1; i < (1<<numberofLevel); i += 2) {
int idx = pattern[numberofLevel][i];
if(idx + 1 >= nxt[a].size()) {
if(i < (1<<numberofLevel) - 1) {
Y[leaf[i / 2]] = -root;
}
else {
Y[leaf[i / 2]] = nxt[a].back();
}
}
else {
Y[leaf[i / 2]] = nxt[a][idx];
}
}
}
}
while(X.back() == INF) {
X.pop_back();
}
while(Y.back() == INF) {
Y.pop_back();
}
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:42:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < pattern[j - 1].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
doll.cpp:45:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 0; i < pattern[j].size(); i += 2) {
| ~~^~~~~~~~~~~~~~~~~~~
doll.cpp:83:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | if(idx + 1 >= nxt[a].size()) {
| ~~~~~~~~^~~~~~~~~~~~~~~~
doll.cpp:92:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | if(idx + 1 >= nxt[a].size()) {
| ~~~~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19284 KB |
Output is correct |
2 |
Correct |
49 ms |
26532 KB |
Output is correct |
3 |
Correct |
41 ms |
26228 KB |
Output is correct |
4 |
Correct |
11 ms |
19284 KB |
Output is correct |
5 |
Correct |
18 ms |
20480 KB |
Output is correct |
6 |
Correct |
67 ms |
29848 KB |
Output is correct |
7 |
Correct |
11 ms |
19264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19284 KB |
Output is correct |
2 |
Correct |
49 ms |
26532 KB |
Output is correct |
3 |
Correct |
41 ms |
26228 KB |
Output is correct |
4 |
Correct |
11 ms |
19284 KB |
Output is correct |
5 |
Correct |
18 ms |
20480 KB |
Output is correct |
6 |
Correct |
67 ms |
29848 KB |
Output is correct |
7 |
Correct |
11 ms |
19264 KB |
Output is correct |
8 |
Correct |
89 ms |
31916 KB |
Output is correct |
9 |
Correct |
95 ms |
32544 KB |
Output is correct |
10 |
Correct |
164 ms |
38688 KB |
Output is correct |
11 |
Correct |
12 ms |
19284 KB |
Output is correct |
12 |
Correct |
12 ms |
19252 KB |
Output is correct |
13 |
Correct |
12 ms |
19312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19284 KB |
Output is correct |
2 |
Correct |
49 ms |
26532 KB |
Output is correct |
3 |
Correct |
41 ms |
26228 KB |
Output is correct |
4 |
Correct |
11 ms |
19284 KB |
Output is correct |
5 |
Correct |
18 ms |
20480 KB |
Output is correct |
6 |
Correct |
67 ms |
29848 KB |
Output is correct |
7 |
Correct |
11 ms |
19264 KB |
Output is correct |
8 |
Correct |
89 ms |
31916 KB |
Output is correct |
9 |
Correct |
95 ms |
32544 KB |
Output is correct |
10 |
Correct |
164 ms |
38688 KB |
Output is correct |
11 |
Correct |
12 ms |
19284 KB |
Output is correct |
12 |
Correct |
12 ms |
19252 KB |
Output is correct |
13 |
Correct |
12 ms |
19312 KB |
Output is correct |
14 |
Incorrect |
174 ms |
39984 KB |
wrong motion |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
19284 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
12 ms |
19284 KB |
Output is partially correct |
2 |
Correct |
49 ms |
25188 KB |
Output is correct |
3 |
Partially correct |
74 ms |
26960 KB |
Output is partially correct |
4 |
Partially correct |
78 ms |
28220 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
12 ms |
19284 KB |
Output is partially correct |
2 |
Correct |
49 ms |
25188 KB |
Output is correct |
3 |
Partially correct |
74 ms |
26960 KB |
Output is partially correct |
4 |
Partially correct |
78 ms |
28220 KB |
Output is partially correct |
5 |
Incorrect |
201 ms |
40856 KB |
wrong motion |
6 |
Halted |
0 ms |
0 KB |
- |