#include "circuit.h"
#include <bits/stdc++.h>
using ll = long long;
const ll mod = 1e9+2022;
int N, M;
std::vector<int> A;
std::vector<int> adj[200005];
std::pair<int, int> DP[200005];
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
::N = N; ::M = M; ::A = A;
for(int i=1;i<P.size();i++) {
adj[P[i]].push_back(i);
}
}
int count_ways(int L, int R) {
for(int i=L;i<=R;i++) A[i-N] ^= 1;
for(int i=N+M-1;i>=0;i--) {
if(i >= N) {
if(A[i-N]) DP[i] = {0, 1};
else DP[i] = {1, 0};
continue;
}
ll tot = adj[i].size();
DP[i].first = DP[i].second = 0;
ll cmult = 1;
for(auto e:adj[i]) {
tot = tot*(DP[e].first + DP[e].second)%mod;
DP[i].second = (DP[i].second*DP[e].first+(cmult+DP[i].second)*DP[e].second) % mod;
cmult = cmult*(DP[e].first + DP[e].second) % mod;
}
DP[i].first = (tot-DP[i].second);
if(DP[i].first < 0) DP[i].first += mod;
}
//for(int i=N+M-1;i>=0;i--) std::cout << i << ": " << DP[i].first << ' ' << DP[i].second << '\n';
return DP[0].second;
}
/*
int main() {
init(3, 4, {-1, 0, 1, 2, 1, 1, 0}, {1, 0, 1, 0});
std::cout << count_ways(3, 4) << '\n';
std::cout << count_ways(4, 5) << '\n';
std::cout << count_ways(3, 6) << '\n';
}*/
Compilation message
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:13:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i=1;i<P.size();i++) {
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '679319622' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '679319622' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3037 ms |
6984 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3037 ms |
6984 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '679319622' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '679319622' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '679319622' |
11 |
Halted |
0 ms |
0 KB |
- |