#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, MOD = 1000002022;
vector<vector<int> > g(2e5);
vector<vector<ll> > dp(3e3, vector<ll>(3e3, 0));
vector<ll> dp0(3e3, 0);
vector<ll> dp1(3e3, 0);
void init(int N, int M, vector<int> P, vector<int> A) {
n = N;
m = M;
for (int i = 1; i < n + m; i++) g[P[i]].push_back(i);
for (int i = 0; i < m; i++) (A[i] ? dp1[i + n] = 1 : dp0[i + n] = 1);
}
void solve(int i) {
for (int k: g[i]) {
for (int j = n; j >= 1; j--) {
dp[i][j] = (dp[i][j] * dp0[k] + dp[i][j - 1] * dp1[k]) % MOD;
}
dp[i][0]=(dp[i][0]*dp0[k])%MOD;
}
ll x0 = dp[i][0], x1 = 0;
for (int j = 1; j <= n; j++) x1 += dp[i][j];
for (int j = 1; j <= g[i].size(); j++) {
dp0[i] += x0;
dp1[i] += x1;
x0 += dp[i][j];
x1 -= dp[i][j];
}
dp0[i] %= MOD;
dp1[i] %= MOD;
}
int count_ways(int L, int R) {
for (int i = 0; i < n; i++) {
fill(dp[i].begin(), dp[i].end(), 0);
dp[i][0] = 1;
dp0[i] = dp1[i] = 0;
}
for (int i = L; i <= R; i++) swap(dp0[i], dp1[i]);
for (int i = n - 1; i >= 0; i--) solve(i);
return dp1[0];
}
Compilation message
circuit.cpp: In function 'void solve(int)':
circuit.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int j = 1; j <= g[i].size(); j++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
75512 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
75604 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
75512 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
118 ms |
156080 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
118 ms |
156080 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
75604 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
75512 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
75512 KB |
2nd lines differ - on the 1st token, expected: '2', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |