#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200005;
const int MOD = 1e9 + 2022;
using ll = long long;
int N, M;
vector<int> g[MaxN];
ll dp[MaxN][2];
vector<int> A;
void dfs(int v){
if (v >= N){
int st = A[v - N];
dp[v][st] = 1;
dp[v][!st] = 0;
return;
}
int c = (int) g[v].size();
for (int u : g[v]){
dfs(u);
}
vector<ll> knapsack(c + 1, 0);
knapsack[0] = 1;
dp[v][0] = 0;
dp[v][1] = 0;
long long tot = c;
for (int u : g[v]){
tot = tot * (dp[u][0] + dp[u][1]) % MOD;
for (int i = c; i >= 0; i--){
long long x = knapsack[i] * dp[u][0];
if (i > 0) x += knapsack[i - 1] * dp[u][1];
knapsack[i] = x % MOD;
}
}
for (int i = 1; i <= c; i++){
dp[v][1] += knapsack[i] * i;
dp[v][1] %= MOD;
}
dp[v][0] = tot - dp[v][1];
}
void init(int _N, int _M, vector<int> P, vector<int> _A) {
N = _N, M = _M, A = _A;
for (int i = 1; i < N + M; i++){
g[P[i]].push_back(i);
}
}
int count_ways(int L, int R) {
for (int i = L; i <= R; i++){
A[i - N] ^= 1;
}
dfs(0);
return dp[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
10 ms |
5036 KB |
Output is correct |
4 |
Correct |
11 ms |
5040 KB |
Output is correct |
5 |
Correct |
10 ms |
4944 KB |
Output is correct |
6 |
Correct |
10 ms |
4944 KB |
Output is correct |
7 |
Correct |
10 ms |
5040 KB |
Output is correct |
8 |
Correct |
9 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4944 KB |
2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
10 ms |
5036 KB |
Output is correct |
4 |
Correct |
11 ms |
5040 KB |
Output is correct |
5 |
Correct |
10 ms |
4944 KB |
Output is correct |
6 |
Correct |
10 ms |
4944 KB |
Output is correct |
7 |
Correct |
10 ms |
5040 KB |
Output is correct |
8 |
Correct |
9 ms |
4944 KB |
Output is correct |
9 |
Correct |
4 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3008 ms |
7560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3008 ms |
7560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4944 KB |
2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
10 ms |
5036 KB |
Output is correct |
4 |
Correct |
11 ms |
5040 KB |
Output is correct |
5 |
Correct |
10 ms |
4944 KB |
Output is correct |
6 |
Correct |
10 ms |
4944 KB |
Output is correct |
7 |
Correct |
10 ms |
5040 KB |
Output is correct |
8 |
Correct |
9 ms |
4944 KB |
Output is correct |
9 |
Correct |
4 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
10 ms |
5036 KB |
Output is correct |
4 |
Correct |
11 ms |
5040 KB |
Output is correct |
5 |
Correct |
10 ms |
4944 KB |
Output is correct |
6 |
Correct |
10 ms |
4944 KB |
Output is correct |
7 |
Correct |
10 ms |
5040 KB |
Output is correct |
8 |
Correct |
9 ms |
4944 KB |
Output is correct |
9 |
Correct |
4 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416' |
11 |
Halted |
0 ms |
0 KB |
- |