5405 | 2023-05-12 17:04:49 | szil | Széfnyitás | cpp14 | Wrong answer 16/100 | 3ms | 4696 KiB |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1e18;
const int MAXN = 151;
int s[MAXN][2], s2[50001][2], a[MAXN], 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;
b[1] = 0;
b[2] = 1;
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 2; j++) {
for (int c = 1; c <= 2; c++) {
for (int d = 1; d <= 2; d++) {
s2[1][0] = i;
s2[1][1] = j;
s2[2][0] = c;
s2[2][1] = d;
bool g = true;
for (int start = 1; start <= n && g; start++) {
int left = k;
int stB = 1;
int st = start;
for (int it = 0; it <= 10; it++) {
int o1 = a[st];
int o2 = b[stB];
if (o1 != o2) {
if (left == 0) {
g = false;
break;
}
left--;
}
st = s[st][o2];
stB = s2[stB][o1];
}
}
if (g) {
cout << "2 1\n";
cout << b[1] << " " << s2[1][0] << " " << s2[1][1] << "\n" << b[2] << " " << s2[2][0] << " " << s2[2][1] << "\n";
return 0;
}
}
}
}
}
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 | 1708 KiB | ||||
2 | Accepted | 3ms | 1872 KiB | ||||
subtask2 | 16/16 | ||||||
3 | Accepted | 3ms | 1872 KiB | ||||
4 | Accepted | 3ms | 2080 KiB | ||||
5 | Accepted | 3ms | 2304 KiB | ||||
6 | Accepted | 3ms | 2512 KiB | ||||
7 | Accepted | 3ms | 2732 KiB | ||||
8 | Accepted | 3ms | 2804 KiB | ||||
9 | Accepted | 2ms | 2800 KiB | ||||
10 | Accepted | 3ms | 2936 KiB | ||||
11 | Accepted | 3ms | 3012 KiB | ||||
12 | Accepted | 2ms | 3020 KiB | ||||
13 | Accepted | 3ms | 3144 KiB | ||||
14 | Accepted | 2ms | 3356 KiB | ||||
subtask3 | 0/24 | ||||||
15 | Accepted | 2ms | 3356 KiB | ||||
16 | Wrong answer | 3ms | 3444 KiB | ||||
17 | Wrong answer | 2ms | 3444 KiB | ||||
18 | Wrong answer | 2ms | 3448 KiB | ||||
19 | Wrong answer | 3ms | 3536 KiB | ||||
20 | Wrong answer | 3ms | 3660 KiB | ||||
21 | Wrong answer | 3ms | 3648 KiB | ||||
22 | Wrong answer | 3ms | 3652 KiB | ||||
23 | Wrong answer | 3ms | 3648 KiB | ||||
subtask4 | 0/23 | ||||||
24 | Wrong answer | 3ms | 3648 KiB | ||||
25 | Wrong answer | 3ms | 3740 KiB | ||||
26 | Wrong answer | 2ms | 3648 KiB | ||||
27 | Wrong answer | 3ms | 3780 KiB | ||||
28 | Wrong answer | 3ms | 3996 KiB | ||||
29 | Wrong answer | 3ms | 3992 KiB | ||||
30 | Wrong answer | 3ms | 4056 KiB | ||||
31 | Wrong answer | 3ms | 4312 KiB | ||||
32 | Wrong answer | 2ms | 4204 KiB | ||||
subtask5 | 0/37 | ||||||
33 | Wrong answer | 2ms | 4204 KiB | ||||
34 | Accepted | 3ms | 2080 KiB | ||||
35 | Accepted | 3ms | 2304 KiB | ||||
36 | Accepted | 3ms | 2512 KiB | ||||
37 | Accepted | 3ms | 2732 KiB | ||||
38 | Accepted | 3ms | 2804 KiB | ||||
39 | Accepted | 2ms | 2800 KiB | ||||
40 | Accepted | 3ms | 2936 KiB | ||||
41 | Accepted | 3ms | 3012 KiB | ||||
42 | Accepted | 2ms | 3020 KiB | ||||
43 | Accepted | 3ms | 3144 KiB | ||||
44 | Accepted | 2ms | 3356 KiB | ||||
45 | Wrong answer | 3ms | 3444 KiB | ||||
46 | Wrong answer | 2ms | 3444 KiB | ||||
47 | Wrong answer | 2ms | 3448 KiB | ||||
48 | Wrong answer | 3ms | 3536 KiB | ||||
49 | Wrong answer | 3ms | 3660 KiB | ||||
50 | Wrong answer | 3ms | 3648 KiB | ||||
51 | Wrong answer | 3ms | 3652 KiB | ||||
52 | Wrong answer | 3ms | 3648 KiB | ||||
53 | Wrong answer | 3ms | 3740 KiB | ||||
54 | Wrong answer | 2ms | 3648 KiB | ||||
55 | Wrong answer | 3ms | 3780 KiB | ||||
56 | Wrong answer | 3ms | 3996 KiB | ||||
57 | Wrong answer | 3ms | 3992 KiB | ||||
58 | Wrong answer | 3ms | 4056 KiB | ||||
59 | Wrong answer | 3ms | 4312 KiB | ||||
60 | Wrong answer | 2ms | 4204 KiB | ||||
61 | Wrong answer | 3ms | 4272 KiB | ||||
62 | Wrong answer | 3ms | 4264 KiB | ||||
63 | Wrong answer | 3ms | 4376 KiB | ||||
64 | Wrong answer | 3ms | 4368 KiB | ||||
65 | Wrong answer | 3ms | 4360 KiB | ||||
66 | Wrong answer | 3ms | 4360 KiB | ||||
67 | Wrong answer | 3ms | 4360 KiB | ||||
68 | Wrong answer | 2ms | 4360 KiB | ||||
69 | Wrong answer | 3ms | 4268 KiB | ||||
70 | Wrong answer | 3ms | 4484 KiB | ||||
71 | Wrong answer | 3ms | 4696 KiB | ||||
72 | Wrong answer | 3ms | 4480 KiB |