104012024-04-01 19:58:54Valaki2Lámpákcpp17Wrong answer 30/10028ms12472 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 15;
const int logk = 31;

int n, k, q;
int par[1 + maxn];
int nxt[1 << maxn];
int ans[1 << maxn];
int lift[1 << maxn][logk];

int find_nxt(int mask) {
    vector<int> state(1 + n, 0);
    for(int i = 1; i <= n; i++) {
        state[i] = (mask >> (i - 1)) & 1;
    }
    vector<int> subtreexor(1 + n, 0);
    for(int i = n; i >= 1; i--) {
        int prevxor = subtreexor[i];
        subtreexor[i] ^= state[i];
        state[i] ^= prevxor;
        subtreexor[par[i]] ^= subtreexor[i];
    }
    int res = 0;
    for(int i = 1; i <= n; i++) {
        res += (1 << (i - 1)) * state[i];
    }
    return res;
}

void solve() {
    cin >> n >> k >> q;
    for(int i = 2; i <= n; i++) {
        cin >> par[i];
    }
    for(int i = 0; i < (1 << n); i++) {
        nxt[i] = find_nxt(i);
    }
    for(int i = 0; i < (1 << n); i++) {
        lift[i][0] = nxt[i];
    }
    for(int j = 1; j < logk; j++) {
        for(int i = 0; i < (1 << n); i++) {
            lift[i][j] = lift[lift[i][j - 1]][j - 1];
        }
    }
    for(int i = 0; i < (1 << n); i++) {
        ans[i] = i;
        for(int j = logk - 1; j >= 0; j--) {
            if((1 << j) & k) {
                ans[i] = lift[ans[i]][j];
            }
        }
    }
    for(int qi = 1; qi <= q; qi++) {
        int mask = 0;
        for(int i = 0; i < n; i++) {
            int x;
            cin >> x;
            mask += x * (1 << i);
        }
        cout << (ans[mask] & 1) << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1848 KiB
2Accepted4ms3196 KiB
subtask20/15
3Wrong answer3ms2376 KiB
4Wrong answer3ms2712 KiB
5Wrong answer3ms2948 KiB
subtask30/10
6Wrong answer3ms3048 KiB
7Wrong answer3ms2668 KiB
8Runtime error14ms11344 KiB
9Runtime error4ms5304 KiB
10Runtime error7ms3348 KiB
subtask430/30
11Accepted28ms11436 KiB
12Accepted28ms11496 KiB
13Accepted28ms11496 KiB
14Accepted28ms11496 KiB
15Accepted28ms11500 KiB
16Accepted28ms11504 KiB
17Accepted28ms11756 KiB
subtask50/45
18Wrong answer3ms3332 KiB
19Runtime error14ms11940 KiB
20Runtime error16ms12136 KiB
21Runtime error7ms4068 KiB
22Runtime error7ms4064 KiB
23Runtime error14ms12252 KiB
24Runtime error7ms4032 KiB
25Runtime error7ms4280 KiB
26Runtime error7ms4388 KiB
27Runtime error7ms4396 KiB
28Runtime error14ms12472 KiB
29Runtime error8ms8444 KiB