Submission #1053606

# Submission time Handle Problem Language Result Execution time Memory
1053606 2024-08-11T14:16:51 Z Ignut Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 7256 KB
/* Ignut
started: 11.08.2024
now: 11.08.2024
████████████████████████████████████████████████████████████████████
████████████████████████████████    ████████████████████████████████
██████████████████████████████        ██████████████████████████████
██████      ██████████████████        ██████████████████      ██████
██████          ██████████████        ██████████████          ██████
██████      ██    ████████████        ████████████    ██      ██████
██████      ████    ██████████        ██████████    ████      ██████
██████      ████      ██████████    ██████████      ████      ██████
██████      ████      ██████████    ██████████    ██████      ██████
██████      ██████    ██████████    ██████████    ██████      ██████
██████      ██████    ████████        ████████    ██████      ██████
██████      ██████      ██████        ██████      ██████      ██████
██████      ████        ████            ████        ████      ██████
██████            ██████████    ████    ██████████            ██████
██████      ██      ██████    ████████    ██████      ██      ██████
██████      ██████            ████████            ██████      ██████
██████                    ██            ██                    ██████
██████████████████████      ████    ████      ██████████████████████
████████████████████████      ██    ██      ████████████████████████
██████████████████████████                ██████████████████████████
██████████████████████████████        ██████████████████████████████
████████████████████████████████████████████████████████████████████
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 2022;

void vadd(int &a, int b) {
    a += a + b >= MOD ? b - MOD : b;
}

int mult(int a, int b) {
    return 1ll * a * b % MOD;
}

// ===================================================== //

const int MAXN = 2e5 + 123;
int n, m;

vector<int> p, a;
vector<int> tree[MAXN];

void init(int N, int M, vector<int> P, vector<int> A) {
    n = N, m = M;
    a = A, p = P;
    for (int i = 0; i < n + m; i ++) {
        if (p[i] == -1) continue;
        tree[p[i]].push_back(i);
    }
}

pair<int, int> dfs(int v) {
    if (v >= n) {
        // cout << v << " : " << (1 ^ a[v - n]) << ", " << a[v - n] << '\n';
        return {1 ^ a[v - n], a[v - n]};
    }

    vector<pair<int, int>> w;
    for (int to : tree[v]) {
        w.push_back(dfs(to));
    }
    int sz = w.size();
    int dp[sz + 1] = {};
    dp[0] = 1;
    for (auto [prob0, prob1] : w) {
        vector<int> nxt(sz + 1, 0);
        for (int i = sz - 1; i >= 0; i --) {
            vadd(nxt[i + 1], mult(dp[i], prob1));
            vadd(nxt[i], mult(dp[i], prob0));
        }
        for (int i = 0; i <= sz; i ++) dp[i] = nxt[i];
    }
    // cout << v << " -- " << sz << '\n';
    // for (int i = 0; i <= sz; i ++) cout << dp[i] << ' ';
    // cout << '\n';
    int r0 = 0, r1 = 0;
    for (int i = 0; i <= sz; i ++) {
        vadd(r1, mult(dp[i], i));
        vadd(r0, mult(dp[i], sz - i));
    }
    // cout << v << " : " << r0 << ", " << r1 << '\n';
    return {r0, r1};
}

int count_ways(int L, int R) {
    L -= n, R -= n;
    for (int i = L; i <= R; i ++) a[i] ^= 1;
    
    int res = (dfs(0)).second;
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 19 ms 4952 KB Output is correct
4 Correct 18 ms 4952 KB Output is correct
5 Correct 18 ms 4952 KB Output is correct
6 Correct 20 ms 4952 KB Output is correct
7 Correct 20 ms 4952 KB Output is correct
8 Correct 18 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 5116 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 1 ms 5208 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 19 ms 4952 KB Output is correct
4 Correct 18 ms 4952 KB Output is correct
5 Correct 18 ms 4952 KB Output is correct
6 Correct 20 ms 4952 KB Output is correct
7 Correct 20 ms 4952 KB Output is correct
8 Correct 18 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4952 KB Output is correct
14 Correct 1 ms 4952 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 1 ms 5116 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 1 ms 5208 KB Output is correct
20 Correct 1 ms 4952 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 1 ms 4952 KB Output is correct
23 Correct 1 ms 4952 KB Output is correct
24 Correct 2 ms 4952 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 1 ms 4952 KB Output is correct
27 Correct 2 ms 4952 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 18 ms 4952 KB Output is correct
30 Correct 18 ms 4952 KB Output is correct
31 Correct 1 ms 5208 KB Output is correct
32 Correct 2 ms 4952 KB Output is correct
33 Correct 1 ms 4952 KB Output is correct
34 Correct 1 ms 4952 KB Output is correct
35 Correct 4 ms 4952 KB Output is correct
36 Correct 1 ms 5208 KB Output is correct
37 Correct 18 ms 5208 KB Output is correct
38 Correct 18 ms 5208 KB Output is correct
39 Correct 1 ms 4952 KB Output is correct
40 Correct 1 ms 4952 KB Output is correct
41 Correct 2 ms 4952 KB Output is correct
42 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3029 ms 7256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3029 ms 7256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 1 ms 5116 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 1 ms 5208 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Execution timed out 3029 ms 7256 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 19 ms 4952 KB Output is correct
4 Correct 18 ms 4952 KB Output is correct
5 Correct 18 ms 4952 KB Output is correct
6 Correct 20 ms 4952 KB Output is correct
7 Correct 20 ms 4952 KB Output is correct
8 Correct 18 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4952 KB Output is correct
14 Correct 1 ms 4952 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 1 ms 5116 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 1 ms 5208 KB Output is correct
20 Correct 1 ms 4952 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 1 ms 4952 KB Output is correct
23 Correct 1 ms 4952 KB Output is correct
24 Correct 2 ms 4952 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 1 ms 4952 KB Output is correct
27 Correct 2 ms 4952 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 18 ms 4952 KB Output is correct
30 Correct 18 ms 4952 KB Output is correct
31 Correct 1 ms 5208 KB Output is correct
32 Correct 2 ms 4952 KB Output is correct
33 Correct 1 ms 4952 KB Output is correct
34 Correct 1 ms 4952 KB Output is correct
35 Correct 4 ms 4952 KB Output is correct
36 Correct 1 ms 5208 KB Output is correct
37 Correct 18 ms 5208 KB Output is correct
38 Correct 18 ms 5208 KB Output is correct
39 Correct 1 ms 4952 KB Output is correct
40 Correct 1 ms 4952 KB Output is correct
41 Correct 2 ms 4952 KB Output is correct
42 Correct 2 ms 4952 KB Output is correct
43 Execution timed out 3054 ms 5208 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 19 ms 4952 KB Output is correct
4 Correct 18 ms 4952 KB Output is correct
5 Correct 18 ms 4952 KB Output is correct
6 Correct 20 ms 4952 KB Output is correct
7 Correct 20 ms 4952 KB Output is correct
8 Correct 18 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4952 KB Output is correct
14 Correct 1 ms 4952 KB Output is correct
15 Correct 1 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 1 ms 5116 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 1 ms 5208 KB Output is correct
20 Correct 1 ms 4952 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 1 ms 4952 KB Output is correct
23 Correct 1 ms 4952 KB Output is correct
24 Correct 2 ms 4952 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 1 ms 4952 KB Output is correct
27 Correct 2 ms 4952 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 18 ms 4952 KB Output is correct
30 Correct 18 ms 4952 KB Output is correct
31 Correct 1 ms 5208 KB Output is correct
32 Correct 2 ms 4952 KB Output is correct
33 Correct 1 ms 4952 KB Output is correct
34 Correct 1 ms 4952 KB Output is correct
35 Correct 4 ms 4952 KB Output is correct
36 Correct 1 ms 5208 KB Output is correct
37 Correct 18 ms 5208 KB Output is correct
38 Correct 18 ms 5208 KB Output is correct
39 Correct 1 ms 4952 KB Output is correct
40 Correct 1 ms 4952 KB Output is correct
41 Correct 2 ms 4952 KB Output is correct
42 Correct 2 ms 4952 KB Output is correct
43 Execution timed out 3029 ms 7256 KB Time limit exceeded
44 Halted 0 ms 0 KB -