#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
using ll = long long;
constexpr ll INF = 1000000000;
ll nxt = -2;
void connect(ll x, vector<int> &X, vector<int> &Y, ll idx) {
// cout << x << '\n';
if (X[idx] == 0) {
X[idx] = x;
}
else {
Y[idx] = x;
}
}
void distribute(ll sz, vector<int> &X, vector<int> &Y, vector<int> &A, ll idx) {
// cout << idx << ' ' << sz << ' ' << ex << endl;
if (idx >= X.size()) {
X.resize(idx + 1);
}
if (idx >= Y.size()) {
Y.resize(idx + 1);
}
// cout << sz << ' ' << e << '\n';
X[idx] = 0;
Y[idx] = 0;
if (sz == 2) {
connect(INF, X, Y, idx);
connect(INF, X, Y, idx);
return;
}
X[idx] = nxt;
nxt--;
Y[idx] = nxt;
nxt--;
distribute(sz / 2, X, Y, A, -X[idx] - 1);
distribute(sz / 2, X, Y, A, -Y[idx] - 1);
}
void create_circuit(int M, vector<int> A) {
ll NN = A.size();
A.push_back(-1);
ll N = A.size();
ll y = 0;
ll ex = 1;
while (ex < N) {
ex *= 2;
}
while (A.size() < ex) {
A.push_back(-1);
}
N = A.size();
A[N - 1] = 0;
vector<int> C, X, Y;
C.push_back(-1);
for (int i = 0; i < M; i++) {
C.push_back(-1);
}
distribute(N, X, Y, A, 0);
// for (int i = 0; i < C.size(); i++) {
// cout << C[i] << '\n';
// }
// cout << conn << '\n';
ll pos = 0, cnt = 0;
vector<bool> state(X.size());
// for (int i = 0; i < X.size(); i++) {
// cout << X[i] << ' ' << Y[i] << endl;
// }
do {
if (pos >= 0) {
pos = C[pos];
}
else {
if (state[-pos - 1] == 0) {
if (X[-pos - 1] == INF) {
X[-pos - 1] = A[cnt++];
}
state[-pos - 1] = !state[-pos - 1];
pos = X[-pos - 1];
}
else {
if (Y[-pos - 1] == INF) {
Y[-pos - 1] = A[cnt++];
}
state[-pos - 1] = !state[-pos - 1];
pos = Y[-pos - 1];
}
}
} while (pos != 0);
// for (int i = 0; i < X.size(); i++) {
// cout << '\t' << X[i] << ' ' << Y[i] << endl;
// }
if (X.size() > NN * 2) {
exit(-1);
// C[0] = 0;
}
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void distribute(ll, std::vector<int>&, std::vector<int>&, std::vector<int>&, ll)':
doll.cpp:23:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if (idx >= X.size()) {
| ~~~~^~~~~~~~~~~
doll.cpp:26:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if (idx >= Y.size()) {
| ~~~~^~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:54:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
54 | while (A.size() < ex) {
| ~~~~~~~~~^~~~
doll.cpp:98:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
98 | if (X.size() > NN * 2) {
| ~~~~~~~~~^~~~~~~~
doll.cpp:49:8: warning: unused variable 'y' [-Wunused-variable]
49 | ll y = 0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Partially correct |
89 ms |
8252 KB |
Output is partially correct |
3 |
Partially correct |
93 ms |
8052 KB |
Output is partially correct |
4 |
Partially correct |
97 ms |
8516 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Partially correct |
89 ms |
8252 KB |
Output is partially correct |
3 |
Partially correct |
93 ms |
8052 KB |
Output is partially correct |
4 |
Partially correct |
97 ms |
8516 KB |
Output is partially correct |
5 |
Partially correct |
100 ms |
9284 KB |
Output is partially correct |
6 |
Partially correct |
115 ms |
8768 KB |
Output is partially correct |
7 |
Partially correct |
99 ms |
8772 KB |
Output is partially correct |
8 |
Partially correct |
99 ms |
9020 KB |
Output is partially correct |
9 |
Partially correct |
94 ms |
8056 KB |
Output is partially correct |
10 |
Partially correct |
93 ms |
8556 KB |
Output is partially correct |
11 |
Partially correct |
97 ms |
8744 KB |
Output is partially correct |
12 |
Partially correct |
92 ms |
8256 KB |
Output is partially correct |
13 |
Partially correct |
96 ms |
8784 KB |
Output is partially correct |
14 |
Partially correct |
95 ms |
8468 KB |
Output is partially correct |
15 |
Partially correct |
93 ms |
8584 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
604 KB |
Output is partially correct |
17 |
Correct |
52 ms |
5660 KB |
Output is correct |
18 |
Partially correct |
95 ms |
8056 KB |
Output is partially correct |
19 |
Partially correct |
92 ms |
8276 KB |
Output is partially correct |
20 |
Partially correct |
117 ms |
9028 KB |
Output is partially correct |
21 |
Partially correct |
97 ms |
8768 KB |
Output is partially correct |
22 |
Partially correct |
97 ms |
8764 KB |
Output is partially correct |