#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;
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++) {
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();
}
// for(auto x : X) {
// cout << x << ' ';
// }
// cout << endl;
// for(auto y : Y) {
// cout << y << ' ';
// }
// cout << endl;
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0; i < pattern[j - 1].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
doll.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0; i < pattern[j].size(); i += 2) {
| ~~^~~~~~~~~~~~~~~~~~~
doll.cpp:75:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | if(idx + 1 >= nxt[a].size()) {
| ~~~~~~~~^~~~~~~~~~~~~~~~
doll.cpp:84:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | if(idx + 1 >= nxt[a].size()) {
| ~~~~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14548 KB |
Output is correct |
2 |
Correct |
44 ms |
18780 KB |
Output is correct |
3 |
Correct |
31 ms |
18480 KB |
Output is correct |
4 |
Correct |
8 ms |
14620 KB |
Output is correct |
5 |
Correct |
19 ms |
15752 KB |
Output is correct |
6 |
Correct |
36 ms |
20548 KB |
Output is correct |
7 |
Correct |
8 ms |
14552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14548 KB |
Output is correct |
2 |
Correct |
44 ms |
18780 KB |
Output is correct |
3 |
Correct |
31 ms |
18480 KB |
Output is correct |
4 |
Correct |
8 ms |
14620 KB |
Output is correct |
5 |
Correct |
19 ms |
15752 KB |
Output is correct |
6 |
Correct |
36 ms |
20548 KB |
Output is correct |
7 |
Correct |
8 ms |
14552 KB |
Output is correct |
8 |
Correct |
56 ms |
21044 KB |
Output is correct |
9 |
Correct |
57 ms |
21572 KB |
Output is correct |
10 |
Correct |
73 ms |
23836 KB |
Output is correct |
11 |
Correct |
10 ms |
14548 KB |
Output is correct |
12 |
Correct |
9 ms |
14548 KB |
Output is correct |
13 |
Correct |
8 ms |
14548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14548 KB |
Output is correct |
2 |
Correct |
44 ms |
18780 KB |
Output is correct |
3 |
Correct |
31 ms |
18480 KB |
Output is correct |
4 |
Correct |
8 ms |
14620 KB |
Output is correct |
5 |
Correct |
19 ms |
15752 KB |
Output is correct |
6 |
Correct |
36 ms |
20548 KB |
Output is correct |
7 |
Correct |
8 ms |
14552 KB |
Output is correct |
8 |
Correct |
56 ms |
21044 KB |
Output is correct |
9 |
Correct |
57 ms |
21572 KB |
Output is correct |
10 |
Correct |
73 ms |
23836 KB |
Output is correct |
11 |
Correct |
10 ms |
14548 KB |
Output is correct |
12 |
Correct |
9 ms |
14548 KB |
Output is correct |
13 |
Correct |
8 ms |
14548 KB |
Output is correct |
14 |
Correct |
112 ms |
25320 KB |
Output is correct |
15 |
Correct |
46 ms |
20388 KB |
Output is correct |
16 |
Correct |
67 ms |
23600 KB |
Output is correct |
17 |
Correct |
8 ms |
14500 KB |
Output is correct |
18 |
Correct |
11 ms |
14564 KB |
Output is correct |
19 |
Correct |
9 ms |
14592 KB |
Output is correct |
20 |
Correct |
102 ms |
25004 KB |
Output is correct |
21 |
Correct |
12 ms |
14556 KB |
Output is correct |
22 |
Correct |
9 ms |
14548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
14616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
9 ms |
14548 KB |
Output is partially correct |
2 |
Correct |
44 ms |
20148 KB |
Output is correct |
3 |
Partially correct |
70 ms |
22100 KB |
Output is partially correct |
4 |
Partially correct |
91 ms |
22956 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
9 ms |
14548 KB |
Output is partially correct |
2 |
Correct |
44 ms |
20148 KB |
Output is correct |
3 |
Partially correct |
70 ms |
22100 KB |
Output is partially correct |
4 |
Partially correct |
91 ms |
22956 KB |
Output is partially correct |
5 |
Partially correct |
95 ms |
25240 KB |
Output is partially correct |
6 |
Partially correct |
112 ms |
26620 KB |
Output is partially correct |
7 |
Partially correct |
101 ms |
26400 KB |
Output is partially correct |
8 |
Partially correct |
115 ms |
26892 KB |
Output is partially correct |
9 |
Partially correct |
76 ms |
22208 KB |
Output is partially correct |
10 |
Partially correct |
104 ms |
26896 KB |
Output is partially correct |
11 |
Partially correct |
118 ms |
27148 KB |
Output is partially correct |
12 |
Partially correct |
77 ms |
22728 KB |
Output is partially correct |
13 |
Partially correct |
73 ms |
22344 KB |
Output is partially correct |
14 |
Partially correct |
87 ms |
22132 KB |
Output is partially correct |
15 |
Partially correct |
75 ms |
21920 KB |
Output is partially correct |
16 |
Partially correct |
10 ms |
14808 KB |
Output is partially correct |
17 |
Partially correct |
61 ms |
21024 KB |
Output is partially correct |
18 |
Partially correct |
58 ms |
21016 KB |
Output is partially correct |
19 |
Partially correct |
57 ms |
21436 KB |
Output is partially correct |
20 |
Partially correct |
76 ms |
23740 KB |
Output is partially correct |
21 |
Partially correct |
96 ms |
25412 KB |
Output is partially correct |
22 |
Partially correct |
71 ms |
23040 KB |
Output is partially correct |