//Dost SEFEROĞLU
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+2022,N = 1e4+1; //division yok
int add(int x,int y) {
return ((x+y) >= MOD ? x+y-MOD : x+y);
}
int mult(int x,int y){
return ((x%MOD)*(y%MOD))%MOD;
}
vi edges[N],dp(N,0),dp2(N,0),c(N);
void dfs(int node) {
for (auto it : edges[node]) dfs(it);
if (edges[node].empty()) {
dp[node] = c[node],dp2[node] = !c[node];
return;
}
int sz = edges[node].size();
vi dpp(sz+1,0),dpp2(sz+1,0);
dpp2[0] = 1;
for (auto it : edges[node]) {
for (int j=0;j<=sz;j++) {
dpp[j] = mult(dpp2[j],dp2[it]);
if (j) dpp[j] = add(dpp[j],mult(dpp2[j-1],dp[it]));
}
for (int j=0;j<=sz;j++) dpp2[j] = dpp[j];
}
dp[node] = dp2[node] = 0;
for (int j=0;j<=sz;j++) {
dp[node] = add(dp[node],mult(j,dpp2[j]));
dp2[node] = add(dp2[node],mult(sz-j,dpp2[j]));
}
}
void init(int32_t N, int32_t M, std::vector<int32_t> P, std::vector<int32_t> A) {
for (int i=1;i<N+M;i++) {
edges[P[i]].push_back(i);
}
for (int i=0;i<M;i++) c[N+i] = A[i];
}
int32_t count_ways(int32_t L, int32_t R) {
for (int i=L;i<=R;i++) c[i]^=1;
dfs(0);
return dp[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
37 ms |
856 KB |
Output is correct |
4 |
Correct |
52 ms |
856 KB |
Output is correct |
5 |
Correct |
55 ms |
1108 KB |
Output is correct |
6 |
Correct |
53 ms |
852 KB |
Output is correct |
7 |
Correct |
52 ms |
856 KB |
Output is correct |
8 |
Correct |
52 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
856 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
856 KB |
Output is correct |
7 |
Correct |
2 ms |
856 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
37 ms |
856 KB |
Output is correct |
4 |
Correct |
52 ms |
856 KB |
Output is correct |
5 |
Correct |
55 ms |
1108 KB |
Output is correct |
6 |
Correct |
53 ms |
852 KB |
Output is correct |
7 |
Correct |
52 ms |
856 KB |
Output is correct |
8 |
Correct |
52 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Correct |
1 ms |
856 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
1 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
1 ms |
856 KB |
Output is correct |
24 |
Correct |
1 ms |
856 KB |
Output is correct |
25 |
Correct |
1 ms |
856 KB |
Output is correct |
26 |
Correct |
1 ms |
856 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
55 ms |
856 KB |
Output is correct |
30 |
Correct |
57 ms |
856 KB |
Output is correct |
31 |
Correct |
1 ms |
856 KB |
Output is correct |
32 |
Correct |
1 ms |
856 KB |
Output is correct |
33 |
Correct |
1 ms |
856 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
9 ms |
856 KB |
Output is correct |
36 |
Correct |
1 ms |
852 KB |
Output is correct |
37 |
Correct |
39 ms |
856 KB |
Output is correct |
38 |
Correct |
40 ms |
856 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
1 ms |
856 KB |
Output is correct |
41 |
Correct |
1 ms |
856 KB |
Output is correct |
42 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
3672 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
3672 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
856 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
856 KB |
Output is correct |
7 |
Correct |
2 ms |
856 KB |
Output is correct |
8 |
Correct |
1 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Runtime error |
8 ms |
3672 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
37 ms |
856 KB |
Output is correct |
4 |
Correct |
52 ms |
856 KB |
Output is correct |
5 |
Correct |
55 ms |
1108 KB |
Output is correct |
6 |
Correct |
53 ms |
852 KB |
Output is correct |
7 |
Correct |
52 ms |
856 KB |
Output is correct |
8 |
Correct |
52 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Correct |
1 ms |
856 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
1 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
1 ms |
856 KB |
Output is correct |
24 |
Correct |
1 ms |
856 KB |
Output is correct |
25 |
Correct |
1 ms |
856 KB |
Output is correct |
26 |
Correct |
1 ms |
856 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
55 ms |
856 KB |
Output is correct |
30 |
Correct |
57 ms |
856 KB |
Output is correct |
31 |
Correct |
1 ms |
856 KB |
Output is correct |
32 |
Correct |
1 ms |
856 KB |
Output is correct |
33 |
Correct |
1 ms |
856 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
9 ms |
856 KB |
Output is correct |
36 |
Correct |
1 ms |
852 KB |
Output is correct |
37 |
Correct |
39 ms |
856 KB |
Output is correct |
38 |
Correct |
40 ms |
856 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
1 ms |
856 KB |
Output is correct |
41 |
Correct |
1 ms |
856 KB |
Output is correct |
42 |
Correct |
2 ms |
856 KB |
Output is correct |
43 |
Execution timed out |
3050 ms |
856 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
37 ms |
856 KB |
Output is correct |
4 |
Correct |
52 ms |
856 KB |
Output is correct |
5 |
Correct |
55 ms |
1108 KB |
Output is correct |
6 |
Correct |
53 ms |
852 KB |
Output is correct |
7 |
Correct |
52 ms |
856 KB |
Output is correct |
8 |
Correct |
52 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Correct |
1 ms |
856 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
1 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
1 ms |
856 KB |
Output is correct |
19 |
Correct |
1 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
1 ms |
856 KB |
Output is correct |
24 |
Correct |
1 ms |
856 KB |
Output is correct |
25 |
Correct |
1 ms |
856 KB |
Output is correct |
26 |
Correct |
1 ms |
856 KB |
Output is correct |
27 |
Correct |
1 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
55 ms |
856 KB |
Output is correct |
30 |
Correct |
57 ms |
856 KB |
Output is correct |
31 |
Correct |
1 ms |
856 KB |
Output is correct |
32 |
Correct |
1 ms |
856 KB |
Output is correct |
33 |
Correct |
1 ms |
856 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
9 ms |
856 KB |
Output is correct |
36 |
Correct |
1 ms |
852 KB |
Output is correct |
37 |
Correct |
39 ms |
856 KB |
Output is correct |
38 |
Correct |
40 ms |
856 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
1 ms |
856 KB |
Output is correct |
41 |
Correct |
1 ms |
856 KB |
Output is correct |
42 |
Correct |
2 ms |
856 KB |
Output is correct |
43 |
Runtime error |
8 ms |
3672 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |