#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000002022;
int n, m;
vector<int> p, a;
vector<int> child[2023];
ll dp[1023], dp2[2023][2023];
ll dpAll[1023];
ll getDPAll(int v) {
ll& ret = dpAll[v] = (int)child[v].size();
for (int i : child[v]) {
if (i < n)
ret = ret * getDPAll(i) % MOD;
}
return ret;
}
void init(int _n, int _m, vector<int> _p, vector<int> _a) {
n = _n;
m = _m;
p = _p;
a = _a;
for (int i = 1; i < n + m; i++)
child[p[i]].push_back(i);
getDPAll(0);
}
void getDP(int v) {
int sz = (int)child[v].size();
for (int i : child[v]) {
if (i < n)
getDP(i);
}
dp2[0][0] = 1;
for (int i = 1; i <= sz; i++) {
int cur = child[v][i - 1];
for (int j = 0; j <= i; j++) {
dp2[i][j] = 0;
if (cur < n)
dp2[i][j] = dp2[i - 1][j] * ((dpAll[cur] - dp[cur] + MOD) % MOD) % MOD;
else if (!a[cur - n])
dp2[i][j] = dp2[i - 1][j];
}
for (int j = 1; j <= i; j++) {
if (cur < n)
dp2[i][j] = (dp2[i][j] + dp2[i - 1][j - 1] * dp[cur] % MOD) % MOD;
else if (a[cur - n])
dp2[i][j] = dp2[i - 1][j - 1];
}
dp2[i][i + 1] = 0;
}
dp[v] = 0;
for (int i = 1; i <= sz; i++)
dp[v] = (dp[v] + dp2[sz][i] * i % MOD) % MOD;
}
int count_ways(int l, int r) {
for (int i = l - n; i <= r - n; i++)
a[i] ^= 1;
getDP(0);
return dp[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
11 ms |
8016 KB |
Output is correct |
4 |
Correct |
8 ms |
8272 KB |
Output is correct |
5 |
Correct |
7 ms |
8276 KB |
Output is correct |
6 |
Correct |
11 ms |
8272 KB |
Output is correct |
7 |
Correct |
12 ms |
8272 KB |
Output is correct |
8 |
Correct |
9 ms |
8272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 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 |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
11 ms |
8016 KB |
Output is correct |
4 |
Correct |
8 ms |
8272 KB |
Output is correct |
5 |
Correct |
7 ms |
8276 KB |
Output is correct |
6 |
Correct |
11 ms |
8272 KB |
Output is correct |
7 |
Correct |
12 ms |
8272 KB |
Output is correct |
8 |
Correct |
9 ms |
8272 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 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 |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
2 ms |
464 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
9 ms |
8272 KB |
Output is correct |
30 |
Correct |
8 ms |
8240 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 |
4 ms |
1492 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
10 ms |
8400 KB |
Output is correct |
38 |
Correct |
8 ms |
8400 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 |
376 KB |
Output is correct |
42 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
3020 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
3020 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 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 |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
512 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 |
11 ms |
3020 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
11 ms |
8016 KB |
Output is correct |
4 |
Correct |
8 ms |
8272 KB |
Output is correct |
5 |
Correct |
7 ms |
8276 KB |
Output is correct |
6 |
Correct |
11 ms |
8272 KB |
Output is correct |
7 |
Correct |
12 ms |
8272 KB |
Output is correct |
8 |
Correct |
9 ms |
8272 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 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 |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
2 ms |
464 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
9 ms |
8272 KB |
Output is correct |
30 |
Correct |
8 ms |
8240 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 |
4 ms |
1492 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
10 ms |
8400 KB |
Output is correct |
38 |
Correct |
8 ms |
8400 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 |
376 KB |
Output is correct |
42 |
Correct |
1 ms |
464 KB |
Output is correct |
43 |
Runtime error |
2 ms |
720 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
11 ms |
8016 KB |
Output is correct |
4 |
Correct |
8 ms |
8272 KB |
Output is correct |
5 |
Correct |
7 ms |
8276 KB |
Output is correct |
6 |
Correct |
11 ms |
8272 KB |
Output is correct |
7 |
Correct |
12 ms |
8272 KB |
Output is correct |
8 |
Correct |
9 ms |
8272 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 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 |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
2 ms |
464 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
9 ms |
8272 KB |
Output is correct |
30 |
Correct |
8 ms |
8240 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 |
4 ms |
1492 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
10 ms |
8400 KB |
Output is correct |
38 |
Correct |
8 ms |
8400 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 |
376 KB |
Output is correct |
42 |
Correct |
1 ms |
464 KB |
Output is correct |
43 |
Runtime error |
11 ms |
3020 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |