166982025-05-09 16:20:31BucsMateLámpákcpp17Wrong answer 0/10054ms1844 KiB
//ChatGPT megoldas

#include <iostream>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K, Q;
    cin >> N >> K >> Q;

    vector<int> p(N); // p[2]..p[N], p[1] nem használt
    for (int i = 2; i <= N; ++i) {
        cin >> p[i];
    }

    // influence[i] = hány váltást okoz az 1-es toronyon, ha i-ből indul a jel
    vector<int> influence(N + 1, 0); // indexelés: 1-től N-ig
    for (int i = 2; i <= N; ++i) {
        influence[i] = influence[p[i]] + 1;
    }

    // Kezdőállapotokat olvassuk be és számoljuk ki a választ
    for (int q = 0; q < Q; ++q) {
        vector<int> state(N + 1);
        for (int i = 1; i <= N; ++i) {
            cin >> state[i];
        }

        long long toggle_count = 0;
        for (int i = 2; i <= N; ++i) {
            if (state[i] == 1) {
                toggle_count += influence[i];
            }
        }

        // Az 1-es torony kezdőállapota
        int initial = state[1];

        // Teljes váltás = toggle_count * K
        long long total_toggles = toggle_count * 1LL * K;

        int final_state = (initial + total_toggles) % 2;
        cout << final_state << '\n';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms316 KiB
2Wrong answer1ms316 KiB
subtask20/15
3Accepted2ms316 KiB
4Wrong answer17ms316 KiB
5Wrong answer50ms1588 KiB
subtask30/10
6Wrong answer1ms500 KiB
7Wrong answer1ms316 KiB
8Wrong answer1ms316 KiB
9Wrong answer1ms508 KiB
10Wrong answer1ms316 KiB
subtask40/30
11Accepted14ms432 KiB
12Wrong answer14ms436 KiB
13Wrong answer14ms316 KiB
14Wrong answer14ms316 KiB
15Wrong answer14ms436 KiB
16Wrong answer14ms508 KiB
17Wrong answer14ms316 KiB
subtask50/45
18Wrong answer45ms564 KiB
19Wrong answer46ms564 KiB
20Wrong answer45ms756 KiB
21Wrong answer45ms756 KiB
22Wrong answer45ms564 KiB
23Wrong answer54ms1588 KiB
24Wrong answer54ms1844 KiB
25Wrong answer52ms1772 KiB
26Wrong answer54ms1592 KiB
27Wrong answer54ms1592 KiB
28Wrong answer39ms476 KiB
29Wrong answer39ms316 KiB