#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1010;
const int mod = 1000002022;
int n, m, p[maxn], a[maxn];
vector<int> g[maxn];
int dp[maxn][2]; // dp[u][flag] = #ways I can be flag
void sol(int u) {
if(u >= n) {
dp[u][0] = dp[u][1] = 0;
dp[u][a[u-n]] = 1;
// cout << u << " " << dp[u][0] << " " << dp[u][1] << endl;
return;
}
vector<int> qtd; // qtd[x] = # Ways I can have exactly x on
for(int i = 0; i <= (int) g[u].size(); i++) {
qtd.pb(0);
}
qtd[0] = 1;
for(auto v : g[u]) {
sol(v);
for(int i = (int) g[u].size(); i >= 0; i--) {
qtd[i] = qtd[i]*dp[v][0]+(i == 0 ? 0 : qtd[i-1])*dp[v][1];
qtd[i]%= mod;
}
}
dp[u][0] = dp[u][1] = 0;
for(int i = 0; i <= (int) g[u].size(); i++) {
dp[u][0]+= qtd[i]*((int) g[u].size() - i); dp[u][0]%= mod;
dp[u][1]+= qtd[i]*i; dp[u][1]%= mod;
}
// cout << u << " " << dp[u][0] << " " << dp[u][1] << endl;
}
void init(int32_t N, int32_t M, vector<int32_t> P, vector<int32_t> A) {
n = N;
m = M;
for(int i = 1; i < n+m; i++) {
p[i] = P[i];
g[p[i]].pb(i);
}
for(int i = 0; i < m; i++) {
a[i] = A[i];
}
}
int32_t count_ways(int32_t L, int32_t R) {
for(int i = L; i <= R; i++) a[i-n]^=1;
sol(0);
return dp[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
11 ms |
336 KB |
Output is correct |
4 |
Correct |
10 ms |
336 KB |
Output is correct |
5 |
Correct |
10 ms |
336 KB |
Output is correct |
6 |
Correct |
11 ms |
336 KB |
Output is correct |
7 |
Correct |
10 ms |
336 KB |
Output is correct |
8 |
Correct |
11 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
11 ms |
336 KB |
Output is correct |
4 |
Correct |
10 ms |
336 KB |
Output is correct |
5 |
Correct |
10 ms |
336 KB |
Output is correct |
6 |
Correct |
11 ms |
336 KB |
Output is correct |
7 |
Correct |
10 ms |
336 KB |
Output is correct |
8 |
Correct |
11 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 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 |
9 ms |
1336 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
1336 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
11 ms |
336 KB |
Output is correct |
4 |
Correct |
10 ms |
336 KB |
Output is correct |
5 |
Correct |
10 ms |
336 KB |
Output is correct |
6 |
Correct |
11 ms |
336 KB |
Output is correct |
7 |
Correct |
10 ms |
336 KB |
Output is correct |
8 |
Correct |
11 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 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 |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
11 ms |
336 KB |
Output is correct |
4 |
Correct |
10 ms |
336 KB |
Output is correct |
5 |
Correct |
10 ms |
336 KB |
Output is correct |
6 |
Correct |
11 ms |
336 KB |
Output is correct |
7 |
Correct |
10 ms |
336 KB |
Output is correct |
8 |
Correct |
11 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |