#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define fi first
#define se second
const int INF = 1e9+1;
const int P = 1000000007;
const ll LLINF = (ll)1e18+1;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
void make(int &s, int cnt, int root, int idx, int lvl, vector<int> &X, vector<int> &Y) {
if(lvl == 2) {
if(cnt == 1) X[idx] = root;
else X[idx] = INF;
Y[idx] = INF;
} else {
if(cnt > lvl/2) {
X[idx] = -(++s);
X.push_back(0); Y.push_back(0);
make(s, cnt-lvl/2, root, -X[idx]-1, lvl/2, X, Y);
Y[idx] = -(++s);
X.push_back(0); Y.push_back(0);
make(s, lvl/2, root, -Y[idx]-1, lvl/2, X, Y);
} else {
X[idx] = root;
Y[idx] = -(++s);
X.push_back(0); Y.push_back(0);
make(s, cnt, root, -Y[idx]-1, lvl/2, X, Y);
}
}
}
void solve(int &s, int &c, vector<int> &X, vector<int> &Y, vector<int> &nxt) {
if(nxt.size() == 0) {
c = 0;
} else if(nxt.size() == 1) {
c = nxt[0];
} else {
c = -(++s);
X.push_back(0); Y.push_back(0);
int lvl = 1;
while(lvl < nxt.size()) lvl <<= 1;
make(s, nxt.size(), c, -c-1, lvl, X, Y);
//cout << X << Y << "\n";
int here = c, cnt = 0;
vector<bool> chk(s+c+1, true);
while(cnt < nxt.size()) {
//cout << here << " " << c << "\n";
int& there = (chk[-here+c] ? X[-here-1] : Y[-here-1]);
chk[-here+c] = !chk[-here+c];
if(there == INF) {
there = nxt[cnt++];
here = c;
} else here = there;
}
}
}
void create_circuit(int M, vector<int> A) {
vector<int> C(M+1, 0), X, Y;
vector<vector<int>> nxt(C.size());
A.push_back(0);
for(int i = 1; i < A.size(); i++)
nxt[A[i-1]].push_back(A[i]);
C[0] = A[0];
for(int i = 1, s = 0; i < C.size(); i++) {
solve(s, C[i], X, Y, nxt[i]);
//cout << s << "\n" << X << Y << "\n";
}
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void solve(int&, int&, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
doll.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | while(lvl < nxt.size()) lvl <<= 1;
| ~~~~^~~~~~~~~~~~
doll.cpp:55:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | while(cnt < nxt.size()) {
| ~~~~^~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i = 1; i < A.size(); i++)
| ~~^~~~~~~~~~
doll.cpp:74:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i = 1, s = 0; i < C.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
24 ms |
6736 KB |
Output is correct |
3 |
Correct |
19 ms |
5660 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
12 ms |
3756 KB |
Output is correct |
6 |
Correct |
30 ms |
8360 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
24 ms |
6736 KB |
Output is correct |
3 |
Correct |
19 ms |
5660 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
12 ms |
3756 KB |
Output is correct |
6 |
Correct |
30 ms |
8360 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
42 ms |
8208 KB |
Output is correct |
9 |
Correct |
46 ms |
9472 KB |
Output is correct |
10 |
Correct |
67 ms |
12784 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
372 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
24 ms |
6736 KB |
Output is correct |
3 |
Correct |
19 ms |
5660 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
12 ms |
3756 KB |
Output is correct |
6 |
Correct |
30 ms |
8360 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
42 ms |
8208 KB |
Output is correct |
9 |
Correct |
46 ms |
9472 KB |
Output is correct |
10 |
Correct |
67 ms |
12784 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
372 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
81 ms |
12472 KB |
Output is correct |
15 |
Correct |
43 ms |
6940 KB |
Output is correct |
16 |
Correct |
66 ms |
10172 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
78 ms |
12056 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
61 ms |
7176 KB |
Output is correct |
3 |
Correct |
63 ms |
5844 KB |
Output is correct |
4 |
Correct |
93 ms |
8720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
61 ms |
7176 KB |
Output is correct |
3 |
Correct |
63 ms |
5844 KB |
Output is correct |
4 |
Correct |
93 ms |
8720 KB |
Output is correct |
5 |
Partially correct |
85 ms |
12684 KB |
Output is partially correct |
6 |
Partially correct |
87 ms |
12052 KB |
Output is partially correct |
7 |
Partially correct |
90 ms |
12312 KB |
Output is partially correct |
8 |
Partially correct |
77 ms |
11412 KB |
Output is partially correct |
9 |
Partially correct |
58 ms |
5916 KB |
Output is partially correct |
10 |
Partially correct |
90 ms |
10812 KB |
Output is partially correct |
11 |
Partially correct |
71 ms |
10136 KB |
Output is partially correct |
12 |
Partially correct |
46 ms |
7244 KB |
Output is partially correct |
13 |
Partially correct |
55 ms |
7820 KB |
Output is partially correct |
14 |
Partially correct |
55 ms |
8012 KB |
Output is partially correct |
15 |
Partially correct |
56 ms |
8344 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
440 KB |
Output is partially correct |
17 |
Partially correct |
45 ms |
6384 KB |
Output is partially correct |
18 |
Partially correct |
47 ms |
6348 KB |
Output is partially correct |
19 |
Partially correct |
47 ms |
6396 KB |
Output is partially correct |
20 |
Partially correct |
67 ms |
10144 KB |
Output is partially correct |
21 |
Partially correct |
71 ms |
9724 KB |
Output is partially correct |
22 |
Partially correct |
79 ms |
9820 KB |
Output is partially correct |