# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
817185 | 2023-08-09T10:18:09 Z | finn__ | Digital Circuit (IOI22_circuit) | C++17 | 3000 ms | 11672 KB |
#include "circuit.h" #include <bits/stdc++.h> using namespace std; constexpr size_t N = 100000; constexpr int64_t MOD = 1'000'002'022; size_t n, m, p[2 * N]; vector<size_t> g[2 * N]; bitset<2 * N> state; int64_t f[2 * N][2]; void dfs(size_t u) { if (g[u].empty()) return; size_t max_p = g[u].size(); vector<int64_t> h(max_p + 1); h[0] = 1; for (auto const &v : g[u]) { dfs(v); for (size_t i = max_p; i; --i) h[i] = (h[i] * f[v][0] + h[i - 1] * f[v][1]) % MOD; h[0] = (h[0] * f[v][0]) % MOD; } for (size_t i = max_p - 1; i; --i) h[i] += h[i + 1]; f[u][1] = 0; for (size_t i = 1; i <= max_p; ++i) f[u][1] += h[i]; f[u][1] %= MOD; f[u][0] = max_p; for (auto const &v : g[u]) f[u][0] = (f[u][0] * (f[v][0] + f[v][1])) % MOD; f[u][0] = (f[u][0] - f[u][1] + MOD) % MOD; } void recompute_state(size_t u) { while (u != SIZE_MAX) { if (!g[u].empty()) { size_t max_p = g[u].size(); vector<int64_t> h(max_p + 1); h[0] = 1; for (auto const &v : g[u]) { for (size_t i = max_p; i; --i) h[i] = (h[i] * f[v][0] + h[i - 1] * f[v][1]) % MOD; h[0] = (h[0] * f[v][0]) % MOD; } for (size_t i = max_p - 1; i; --i) h[i] += h[i + 1]; f[u][1] = 0; for (size_t i = 1; i <= max_p; ++i) f[u][1] += h[i]; f[u][1] %= MOD; f[u][0] = max_p; for (auto const &v : g[u]) f[u][0] = (f[u][0] * (f[v][0] + f[v][1])) % MOD; f[u][0] = (f[u][0] - f[u][1] + MOD) % MOD; } u = p[u]; } } void init(int n_, int m_, vector<int> p_, vector<int> a) { n = n_, m = m_; for (size_t i = 0; i < n + m; ++i) p[i] = p_[i]; for (size_t i = 0; i < n + m; ++i) if (p[i] != -1) g[p[i]].push_back(i); for (size_t i = 0; i < m; ++i) state[n + i] = a[i], f[n + i][state[n + i]] = 1, f[n + i][!state[n + i]] = 0; dfs(0); } int count_ways(int l, int r) { for (size_t i = l; i <= r; ++i) state[i] = !state[i], f[i][state[i]] = 1, f[i][!state[i]] = 0; if (l == r) recompute_state(l); else dfs(0); return f[0][1]; }
Compilation message
# | 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 | 13 ms | 5076 KB | Output is correct |
4 | Correct | 17 ms | 4952 KB | Output is correct |
5 | Correct | 13 ms | 5072 KB | Output is correct |
6 | Correct | 13 ms | 5072 KB | Output is correct |
7 | Correct | 17 ms | 5076 KB | Output is correct |
8 | Correct | 14 ms | 4944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4944 KB | Output is correct |
2 | Correct | 2 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 | 3 ms | 5072 KB | Output is correct |
8 | Correct | 3 ms | 5072 KB | Output is correct |
9 | Correct | 3 ms | 5072 KB | Output is correct |
10 | Correct | 3 ms | 5200 KB | Output is correct |
11 | Correct | 4 ms | 5200 KB | Output is correct |
12 | Correct | 2 ms | 5072 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 | 13 ms | 5076 KB | Output is correct |
4 | Correct | 17 ms | 4952 KB | Output is correct |
5 | Correct | 13 ms | 5072 KB | Output is correct |
6 | Correct | 13 ms | 5072 KB | Output is correct |
7 | Correct | 17 ms | 5076 KB | Output is correct |
8 | Correct | 14 ms | 4944 KB | Output is correct |
9 | Correct | 3 ms | 4944 KB | Output is correct |
10 | Correct | 2 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 | 3 ms | 5072 KB | Output is correct |
16 | Correct | 3 ms | 5072 KB | Output is correct |
17 | Correct | 3 ms | 5072 KB | Output is correct |
18 | Correct | 3 ms | 5200 KB | Output is correct |
19 | Correct | 4 ms | 5200 KB | Output is correct |
20 | Correct | 2 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 | 5072 KB | Output is correct |
24 | Correct | 2 ms | 5072 KB | Output is correct |
25 | Correct | 4 ms | 5072 KB | Output is correct |
26 | Correct | 4 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 | 14 ms | 4944 KB | Output is correct |
30 | Correct | 14 ms | 5120 KB | Output is correct |
31 | Correct | 3 ms | 5200 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 | 5072 KB | Output is correct |
35 | Correct | 5 ms | 5020 KB | Output is correct |
36 | Correct | 3 ms | 5200 KB | Output is correct |
37 | Correct | 13 ms | 5200 KB | Output is correct |
38 | Correct | 13 ms | 5200 KB | Output is correct |
39 | Correct | 3 ms | 5072 KB | Output is correct |
40 | Correct | 3 ms | 5072 KB | Output is correct |
41 | Correct | 3 ms | 5072 KB | Output is correct |
42 | Correct | 3 ms | 4944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 549 ms | 8272 KB | Output is correct |
2 | Correct | 837 ms | 11660 KB | Output is correct |
3 | Correct | 815 ms | 11672 KB | Output is correct |
4 | Correct | 818 ms | 11664 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 549 ms | 8272 KB | Output is correct |
2 | Correct | 837 ms | 11660 KB | Output is correct |
3 | Correct | 815 ms | 11672 KB | Output is correct |
4 | Correct | 818 ms | 11664 KB | Output is correct |
5 | Execution timed out | 3079 ms | 8332 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4944 KB | Output is correct |
2 | Correct | 2 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 | 3 ms | 5072 KB | Output is correct |
8 | Correct | 3 ms | 5072 KB | Output is correct |
9 | Correct | 3 ms | 5072 KB | Output is correct |
10 | Correct | 3 ms | 5200 KB | Output is correct |
11 | Correct | 4 ms | 5200 KB | Output is correct |
12 | Correct | 2 ms | 5072 KB | Output is correct |
13 | Correct | 549 ms | 8272 KB | Output is correct |
14 | Correct | 837 ms | 11660 KB | Output is correct |
15 | Correct | 815 ms | 11672 KB | Output is correct |
16 | Correct | 818 ms | 11664 KB | Output is correct |
17 | Execution timed out | 3079 ms | 8332 KB | Time limit exceeded |
18 | 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 | 13 ms | 5076 KB | Output is correct |
4 | Correct | 17 ms | 4952 KB | Output is correct |
5 | Correct | 13 ms | 5072 KB | Output is correct |
6 | Correct | 13 ms | 5072 KB | Output is correct |
7 | Correct | 17 ms | 5076 KB | Output is correct |
8 | Correct | 14 ms | 4944 KB | Output is correct |
9 | Correct | 3 ms | 4944 KB | Output is correct |
10 | Correct | 2 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 | 3 ms | 5072 KB | Output is correct |
16 | Correct | 3 ms | 5072 KB | Output is correct |
17 | Correct | 3 ms | 5072 KB | Output is correct |
18 | Correct | 3 ms | 5200 KB | Output is correct |
19 | Correct | 4 ms | 5200 KB | Output is correct |
20 | Correct | 2 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 | 5072 KB | Output is correct |
24 | Correct | 2 ms | 5072 KB | Output is correct |
25 | Correct | 4 ms | 5072 KB | Output is correct |
26 | Correct | 4 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 | 14 ms | 4944 KB | Output is correct |
30 | Correct | 14 ms | 5120 KB | Output is correct |
31 | Correct | 3 ms | 5200 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 | 5072 KB | Output is correct |
35 | Correct | 5 ms | 5020 KB | Output is correct |
36 | Correct | 3 ms | 5200 KB | Output is correct |
37 | Correct | 13 ms | 5200 KB | Output is correct |
38 | Correct | 13 ms | 5200 KB | Output is correct |
39 | Correct | 3 ms | 5072 KB | Output is correct |
40 | Correct | 3 ms | 5072 KB | Output is correct |
41 | Correct | 3 ms | 5072 KB | Output is correct |
42 | Correct | 3 ms | 4944 KB | Output is correct |
43 | Execution timed out | 3046 ms | 5200 KB | Time limit exceeded |
44 | 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 | 13 ms | 5076 KB | Output is correct |
4 | Correct | 17 ms | 4952 KB | Output is correct |
5 | Correct | 13 ms | 5072 KB | Output is correct |
6 | Correct | 13 ms | 5072 KB | Output is correct |
7 | Correct | 17 ms | 5076 KB | Output is correct |
8 | Correct | 14 ms | 4944 KB | Output is correct |
9 | Correct | 3 ms | 4944 KB | Output is correct |
10 | Correct | 2 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 | 3 ms | 5072 KB | Output is correct |
16 | Correct | 3 ms | 5072 KB | Output is correct |
17 | Correct | 3 ms | 5072 KB | Output is correct |
18 | Correct | 3 ms | 5200 KB | Output is correct |
19 | Correct | 4 ms | 5200 KB | Output is correct |
20 | Correct | 2 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 | 5072 KB | Output is correct |
24 | Correct | 2 ms | 5072 KB | Output is correct |
25 | Correct | 4 ms | 5072 KB | Output is correct |
26 | Correct | 4 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 | 14 ms | 4944 KB | Output is correct |
30 | Correct | 14 ms | 5120 KB | Output is correct |
31 | Correct | 3 ms | 5200 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 | 5072 KB | Output is correct |
35 | Correct | 5 ms | 5020 KB | Output is correct |
36 | Correct | 3 ms | 5200 KB | Output is correct |
37 | Correct | 13 ms | 5200 KB | Output is correct |
38 | Correct | 13 ms | 5200 KB | Output is correct |
39 | Correct | 3 ms | 5072 KB | Output is correct |
40 | Correct | 3 ms | 5072 KB | Output is correct |
41 | Correct | 3 ms | 5072 KB | Output is correct |
42 | Correct | 3 ms | 4944 KB | Output is correct |
43 | Correct | 549 ms | 8272 KB | Output is correct |
44 | Correct | 837 ms | 11660 KB | Output is correct |
45 | Correct | 815 ms | 11672 KB | Output is correct |
46 | Correct | 818 ms | 11664 KB | Output is correct |
47 | Execution timed out | 3079 ms | 8332 KB | Time limit exceeded |
48 | Halted | 0 ms | 0 KB | - |