5401 | 2023-05-12 15:55:28 | szil | Széfnyitás | cpp14 | Wrong answer 23/100 | 8ms | 6336 KiB |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1e18;
const int MAXN = 151;
int a[MAXN];
int s[MAXN][2], s2[50001][2], b[50001];
bool bits[MAXN];
int timer;
struct Node {
Node *p[2] = {nullptr, nullptr};
int u = -1, t;
};
Node *root;
void add(vector<int> &v, int u) {
Node *ptr = root;
for (int i : v) {
if (ptr->p[i] == nullptr) {
ptr->p[i] = new Node();
ptr->p[i]->t = timer++;
}
ptr = ptr->p[i];
}
ptr->u = u;
}
void upd(Node *v, int d = 0) {
b[v->t] = bits[d];
if (v->u != -1) {
s2[v->t][0] = s2[v->t][1] = v->u;
return;
}
if (v->p[0] != nullptr) {
s2[v->t][0] = v->p[0]->t;
upd(v->p[0], d + 1);
}
if (v->p[1] != nullptr) {
s2[v->t][1] = v->p[1]->t;
upd(v->p[1], d + 1);
}
}
int main()
{
srand(time(0));
ios::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n;
timer = n + 1;
root = new Node();
root->t = timer++;
for (int i = 1; i <= n; i++) {
int x;
cin >> a[i] >> s[i][0] >> s[i][1];
}
cin >> k;
for (int i = 0; i < n; i++) {
bits[i] = rand() % 2;
}
for (int i = 1; i <= n; i++) {
vector<int> v;
int u = i;
for (int it = 0; it < n-1; it++) {
v.push_back(a[u]);
u = s[u][bits[it]];
}
add(v, s[u][bits[n-1]]);
}
upd(root);
cout << timer-1 << " " << n+1 << "\n";
for (int i = 1; i <= n; i++) {
cout << a[i] << " " << s[i][0] << " " << s[i][1] << "\n";
}
for (int i = n+1; i < timer; i++) {
if (s2[i][0] == 0) s2[i][0] = s2[i][1];
if (s2[i][1] == 0) s2[i][1] = s2[i][0];
if (s2[i][0] == 0) {
s2[i][0] = s2[i][1] = 1;
}
cout << b[i] << " " << s2[i][0] << " " << s2[i][1] << "\n";
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1844 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
subtask2 | 0/16 | ||||||
3 | Accepted | 3ms | 2056 KiB | ||||
4 | Accepted | 3ms | 2244 KiB | ||||
5 | Accepted | 3ms | 2456 KiB | ||||
6 | Wrong answer | 3ms | 2800 KiB | ||||
7 | Wrong answer | 3ms | 2876 KiB | ||||
8 | Accepted | 3ms | 3220 KiB | ||||
9 | Accepted | 2ms | 3176 KiB | ||||
10 | Wrong answer | 3ms | 3260 KiB | ||||
11 | Wrong answer | 3ms | 3472 KiB | ||||
12 | Accepted | 3ms | 3520 KiB | ||||
13 | Wrong answer | 3ms | 3612 KiB | ||||
14 | Wrong answer | 3ms | 3824 KiB | ||||
subtask3 | 0/24 | ||||||
15 | Wrong answer | 3ms | 3824 KiB | ||||
16 | Accepted | 3ms | 3924 KiB | ||||
17 | Accepted | 3ms | 4276 KiB | ||||
18 | Accepted | 3ms | 4296 KiB | ||||
19 | Accepted | 3ms | 4232 KiB | ||||
20 | Accepted | 3ms | 4408 KiB | ||||
21 | Accepted | 3ms | 4396 KiB | ||||
22 | Accepted | 3ms | 4360 KiB | ||||
23 | Accepted | 3ms | 4368 KiB | ||||
subtask4 | 23/23 | ||||||
24 | Accepted | 3ms | 4368 KiB | ||||
25 | Accepted | 3ms | 4492 KiB | ||||
26 | Accepted | 3ms | 4348 KiB | ||||
27 | Accepted | 3ms | 4512 KiB | ||||
28 | Accepted | 3ms | 4436 KiB | ||||
29 | Accepted | 3ms | 4428 KiB | ||||
30 | Accepted | 3ms | 4440 KiB | ||||
31 | Accepted | 3ms | 4696 KiB | ||||
32 | Accepted | 3ms | 4792 KiB | ||||
subtask5 | 0/37 | ||||||
33 | Accepted | 3ms | 4792 KiB | ||||
34 | Accepted | 3ms | 2244 KiB | ||||
35 | Accepted | 3ms | 2456 KiB | ||||
36 | Wrong answer | 3ms | 2800 KiB | ||||
37 | Wrong answer | 3ms | 2876 KiB | ||||
38 | Accepted | 3ms | 3220 KiB | ||||
39 | Accepted | 2ms | 3176 KiB | ||||
40 | Wrong answer | 3ms | 3260 KiB | ||||
41 | Wrong answer | 3ms | 3472 KiB | ||||
42 | Accepted | 3ms | 3520 KiB | ||||
43 | Wrong answer | 3ms | 3612 KiB | ||||
44 | Wrong answer | 3ms | 3824 KiB | ||||
45 | Accepted | 3ms | 3924 KiB | ||||
46 | Accepted | 3ms | 4276 KiB | ||||
47 | Accepted | 3ms | 4296 KiB | ||||
48 | Accepted | 3ms | 4232 KiB | ||||
49 | Accepted | 3ms | 4408 KiB | ||||
50 | Accepted | 3ms | 4396 KiB | ||||
51 | Accepted | 3ms | 4360 KiB | ||||
52 | Accepted | 3ms | 4368 KiB | ||||
53 | Accepted | 3ms | 4492 KiB | ||||
54 | Accepted | 3ms | 4348 KiB | ||||
55 | Accepted | 3ms | 4512 KiB | ||||
56 | Accepted | 3ms | 4436 KiB | ||||
57 | Accepted | 3ms | 4428 KiB | ||||
58 | Accepted | 3ms | 4440 KiB | ||||
59 | Accepted | 3ms | 4696 KiB | ||||
60 | Accepted | 3ms | 4792 KiB | ||||
61 | Accepted | 4ms | 4880 KiB | ||||
62 | Accepted | 6ms | 5608 KiB | ||||
63 | Accepted | 6ms | 5560 KiB | ||||
64 | Accepted | 7ms | 5756 KiB | ||||
65 | Accepted | 7ms | 5812 KiB | ||||
66 | Accepted | 7ms | 5916 KiB | ||||
67 | Accepted | 7ms | 5836 KiB | ||||
68 | Accepted | 7ms | 5940 KiB | ||||
69 | Accepted | 7ms | 5792 KiB | ||||
70 | Accepted | 8ms | 6252 KiB | ||||
71 | Accepted | 7ms | 6336 KiB | ||||
72 | Accepted | 7ms | 6264 KiB |