Submission #793144

# Submission time Handle Problem Language Result Execution time Memory
793144 2023-07-25T14:22:18 Z SlavicG Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 13164 KB
#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
const int N = 2e5 + 5, mod = 1000002022;
vector<int> adj[N];
int64_t dp[N][2], color[N];
void dfs(int u) {
    if(adj[u].size() == 0) {
        if(color[u]) dp[u][0] = 0, dp[u][1] = 1;
        else dp[u][0] = 1, dp[u][1] = 0;
        return;
    }
    for(int v: adj[u]) dfs(v);
    vector<vector<int64_t>> D((int)adj[u].size() + 1, vector<int64_t>((int)adj[u].size() + 1));
    D[0][0] = 1;
    for(int i = 0; i < (int)adj[u].size(); ++i) {
        for(int j = 0; j <= i; ++j) {
            D[i + 1][j] += D[i][j] * dp[adj[u][i]][0] % mod;
            D[i + 1][j] %= mod;
            D[i + 1][j + 1] += D[i][j] * dp[adj[u][i]][1] % mod;
            D[i + 1][j + 1] %= mod; 
        }
    }
    dp[u][0] = dp[u][1] = 0;
    for(int i = 0; i <= (int)adj[u].size(); ++i) {
        dp[u][1] += D[(int)adj[u].size()][i] * i % mod;
        dp[u][1] %= mod;
        dp[u][0] += D[(int)adj[u].size()][i] * ((int)adj[u].size() - i) % mod;
        dp[u][0] %= mod;
    }
} 
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    for(int i = 1; i < N + M; ++i) {
        adj[P[i]].push_back(i);
    }
    for(int i = 0; i < M; ++i) color[i + N] = A[i];
    dfs(0);
}

int count_ways(int L, int R) {
    for(int i = L; i <= R; ++i) {
        color[i] ^= 1;
    }
    dfs(0);
    return dp[0][1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 28 ms 12512 KB Output is correct
4 Correct 29 ms 12992 KB Output is correct
5 Correct 36 ms 12948 KB Output is correct
6 Correct 30 ms 12936 KB Output is correct
7 Correct 29 ms 12944 KB Output is correct
8 Correct 29 ms 12984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 28 ms 12512 KB Output is correct
4 Correct 29 ms 12992 KB Output is correct
5 Correct 36 ms 12948 KB Output is correct
6 Correct 30 ms 12936 KB Output is correct
7 Correct 29 ms 12944 KB Output is correct
8 Correct 29 ms 12984 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 31 ms 12972 KB Output is correct
30 Correct 33 ms 13048 KB Output is correct
31 Correct 4 ms 5192 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 7 ms 5428 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 30 ms 13164 KB Output is correct
38 Correct 30 ms 13160 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3013 ms 8008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3013 ms 8008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Execution timed out 3013 ms 8008 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 28 ms 12512 KB Output is correct
4 Correct 29 ms 12992 KB Output is correct
5 Correct 36 ms 12948 KB Output is correct
6 Correct 30 ms 12936 KB Output is correct
7 Correct 29 ms 12944 KB Output is correct
8 Correct 29 ms 12984 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 31 ms 12972 KB Output is correct
30 Correct 33 ms 13048 KB Output is correct
31 Correct 4 ms 5192 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 7 ms 5428 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 30 ms 13164 KB Output is correct
38 Correct 30 ms 13160 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Execution timed out 3083 ms 5252 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 28 ms 12512 KB Output is correct
4 Correct 29 ms 12992 KB Output is correct
5 Correct 36 ms 12948 KB Output is correct
6 Correct 30 ms 12936 KB Output is correct
7 Correct 29 ms 12944 KB Output is correct
8 Correct 29 ms 12984 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 31 ms 12972 KB Output is correct
30 Correct 33 ms 13048 KB Output is correct
31 Correct 4 ms 5192 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 7 ms 5428 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 30 ms 13164 KB Output is correct
38 Correct 30 ms 13160 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Execution timed out 3013 ms 8008 KB Time limit exceeded
44 Halted 0 ms 0 KB -