#include "circuit.h"
#include "bits/stdc++.h"
using namespace std;
const int MAX_N = 2003;
const int md = 1000002022;
inline int add(int x, int y) {
x += y;
if (x >= md) x -= md;
return x;
}
inline int mul(int x, int y) {
return (int) ((long long) x * y % md);
}
int n, m;
int win[MAX_N];
int lose[MAX_N];
vector<int> a;
vector<int> g[MAX_N];
int dp[MAX_N][MAX_N];
vector<array<int, 2>> dps;
int knapsack(int ind, int k) {
if (ind == (int) dps.size()) {
return k == 0;
}
if (k < 0) {
return 0;
}
int& ret = dp[ind][k];
if (ret != -1) {
return ret;
}
ret = add(mul(knapsack(ind + 1, k), dps[ind][0]), mul(knapsack(ind + 1, k - 1), dps[ind][1]));
return ret;
}
void dfs(int v) {
if (v >= n) {
lose[v] = (a[v - n] == 0);
win[v] = (a[v - n] == 1);
return;
}
for (int u : g[v]) {
dfs(u);
}
for (int u : g[v]) {
dps.push_back({lose[u], win[u]});
}
int ch_num = g[v].size();
for (int i = 0; i < ch_num; ++i) {
for (int j = 0; j <= ch_num; ++j) {
dp[i][j] = -1;
}
}
for (int k = 0; k <= ch_num; ++k) {
int x = knapsack(0, k);
win[v] = add(win[v], mul(k, x));
lose[v] = add(lose[v], mul((ch_num - k), x));
}
dps.clear();
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
for (int i = 1; i < N + M; ++i) {
g[P[i]].push_back(i);
}
n = N;
m = M;
a = A;
}
int count_ways(int L, int R) {
for (int i = L; i <= R; ++i) {
a[i - n] ^= 1;
}
fill(win, win + n, 0);
fill(lose, lose + n, 0);
dfs(0);
return win[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
55 ms |
8016 KB |
Output is correct |
4 |
Correct |
58 ms |
8308 KB |
Output is correct |
5 |
Correct |
58 ms |
8308 KB |
Output is correct |
6 |
Correct |
75 ms |
8312 KB |
Output is correct |
7 |
Correct |
58 ms |
8304 KB |
Output is correct |
8 |
Correct |
58 ms |
8312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
55 ms |
8016 KB |
Output is correct |
4 |
Correct |
58 ms |
8308 KB |
Output is correct |
5 |
Correct |
58 ms |
8308 KB |
Output is correct |
6 |
Correct |
75 ms |
8312 KB |
Output is correct |
7 |
Correct |
58 ms |
8304 KB |
Output is correct |
8 |
Correct |
58 ms |
8312 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
472 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
58 ms |
8312 KB |
Output is correct |
30 |
Correct |
61 ms |
8308 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
12 ms |
1360 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
58 ms |
8448 KB |
Output is correct |
38 |
Correct |
59 ms |
8440 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
2256 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
2256 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Runtime error |
13 ms |
2256 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
55 ms |
8016 KB |
Output is correct |
4 |
Correct |
58 ms |
8308 KB |
Output is correct |
5 |
Correct |
58 ms |
8308 KB |
Output is correct |
6 |
Correct |
75 ms |
8312 KB |
Output is correct |
7 |
Correct |
58 ms |
8304 KB |
Output is correct |
8 |
Correct |
58 ms |
8312 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
472 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
58 ms |
8312 KB |
Output is correct |
30 |
Correct |
61 ms |
8308 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
12 ms |
1360 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
58 ms |
8448 KB |
Output is correct |
38 |
Correct |
59 ms |
8440 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
2 ms |
464 KB |
Output is correct |
43 |
Runtime error |
2 ms |
720 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
55 ms |
8016 KB |
Output is correct |
4 |
Correct |
58 ms |
8308 KB |
Output is correct |
5 |
Correct |
58 ms |
8308 KB |
Output is correct |
6 |
Correct |
75 ms |
8312 KB |
Output is correct |
7 |
Correct |
58 ms |
8304 KB |
Output is correct |
8 |
Correct |
58 ms |
8312 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
472 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
58 ms |
8312 KB |
Output is correct |
30 |
Correct |
61 ms |
8308 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
12 ms |
1360 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
58 ms |
8448 KB |
Output is correct |
38 |
Correct |
59 ms |
8440 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
2 ms |
464 KB |
Output is correct |
43 |
Runtime error |
13 ms |
2256 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |