54052023-05-12 17:04:49szilSzéfnyitáscpp14Wrong answer 16/1003ms4696 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1708 KiB
2Accepted3ms1872 KiB
subtask216/16
3Accepted3ms1872 KiB
4Accepted3ms2080 KiB
5Accepted3ms2304 KiB
6Accepted3ms2512 KiB
7Accepted3ms2732 KiB
8Accepted3ms2804 KiB
9Accepted2ms2800 KiB
10Accepted3ms2936 KiB
11Accepted3ms3012 KiB
12Accepted2ms3020 KiB
13Accepted3ms3144 KiB
14Accepted2ms3356 KiB
subtask30/24
15Accepted2ms3356 KiB
16Wrong answer3ms3444 KiB
17Wrong answer2ms3444 KiB
18Wrong answer2ms3448 KiB
19Wrong answer3ms3536 KiB
20Wrong answer3ms3660 KiB
21Wrong answer3ms3648 KiB
22Wrong answer3ms3652 KiB
23Wrong answer3ms3648 KiB
subtask40/23
24Wrong answer3ms3648 KiB
25Wrong answer3ms3740 KiB
26Wrong answer2ms3648 KiB
27Wrong answer3ms3780 KiB
28Wrong answer3ms3996 KiB
29Wrong answer3ms3992 KiB
30Wrong answer3ms4056 KiB
31Wrong answer3ms4312 KiB
32Wrong answer2ms4204 KiB
subtask50/37
33Wrong answer2ms4204 KiB
34Accepted3ms2080 KiB
35Accepted3ms2304 KiB
36Accepted3ms2512 KiB
37Accepted3ms2732 KiB
38Accepted3ms2804 KiB
39Accepted2ms2800 KiB
40Accepted3ms2936 KiB
41Accepted3ms3012 KiB
42Accepted2ms3020 KiB
43Accepted3ms3144 KiB
44Accepted2ms3356 KiB
45Wrong answer3ms3444 KiB
46Wrong answer2ms3444 KiB
47Wrong answer2ms3448 KiB
48Wrong answer3ms3536 KiB
49Wrong answer3ms3660 KiB
50Wrong answer3ms3648 KiB
51Wrong answer3ms3652 KiB
52Wrong answer3ms3648 KiB
53Wrong answer3ms3740 KiB
54Wrong answer2ms3648 KiB
55Wrong answer3ms3780 KiB
56Wrong answer3ms3996 KiB
57Wrong answer3ms3992 KiB
58Wrong answer3ms4056 KiB
59Wrong answer3ms4312 KiB
60Wrong answer2ms4204 KiB
61Wrong answer3ms4272 KiB
62Wrong answer3ms4264 KiB
63Wrong answer3ms4376 KiB
64Wrong answer3ms4368 KiB
65Wrong answer3ms4360 KiB
66Wrong answer3ms4360 KiB
67Wrong answer3ms4360 KiB
68Wrong answer2ms4360 KiB
69Wrong answer3ms4268 KiB
70Wrong answer3ms4484 KiB
71Wrong answer3ms4696 KiB
72Wrong answer3ms4480 KiB