#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[1010];
int state[1010], n, m;
void init(int N, int M, vector<int> P, vector<int> A) {
n=N;
m=M;
for(int i = 0; i < M; i++)
state[i+N] = A[i];
for(int i = 1; i < n+m; i++)
adj[P[i]].push_back(i);
}
pair<long long, long long> dfs(int N) {
if(N>=n) {
return {!state[N], state[N]};
}
long long dp[1+adj[N].size()]{}, c = adj[N].size();
dp[0] = 1;
for(auto i: adj[N]) {
int a, b;
tie(a,b)=dfs(i);
for(int j= c+1; --j;)
dp[j] = (a*dp[j]+b*dp[j-1])%1000002022;
dp[0] = dp[0]*a%1000002022;
}
long long ans1=0, ans2=0;
for(int i = 0; i <= c; i++)
ans1+=(c-i)*dp[i], ans2+=i*dp[i];
return {ans1%1000002022, ans2%1000002022};
}
int count_ways(int L, int R) {
for(int i = L; i <= R; i++) {
state[i]^=1;
}
return dfs(0).second;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
336 KB |
Output is correct |
4 |
Correct |
9 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
8 |
Correct |
9 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
336 KB |
Output is correct |
4 |
Correct |
9 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
8 |
Correct |
9 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
2000 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
2000 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
336 KB |
Output is correct |
4 |
Correct |
9 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
8 |
Correct |
9 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
336 KB |
Output is correct |
4 |
Correct |
9 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
8 |
Correct |
9 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |