#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000002022;
int n, m;
vector<int> p, a;
vector<int> child[2023];
ll dp[1023], dp2[2023][2023];
ll dpAll[1023];
ll getDPAll(int v) {
ll& ret = dpAll[v] = (int)child[v].size();
for (int i : child[v]) {
if (i < n)
ret = ret * getDPAll(i) % MOD;
}
return ret;
}
void init(int _n, int _m, vector<int> _p, vector<int> _a) {
n = _n;
m = _m;
p = _p;
a = _a;
for (int i = 1; i < n + m; i++)
child[p[i]].push_back(i);
getDPAll(0);
}
void getDP(int v) {
int sz = (int)child[v].size();
for (int i : child[v]) {
if (i < n)
getDP(i);
}
dp2[0][0] = 1;
ll tmp = 1;
for (int i = 1; i <= sz; i++) {
int cur = child[v][i - 1];
ll tmp2 = 0;
for (int j = 1; j <= i; j++) {
if (cur < n) {
tmp = tmp * dpAll[cur] % MOD;
dp2[i][j] = (dp2[i - 1][j - 1] * dp[cur] % MOD + dp2[i - 1][j] * ((dpAll[cur] - dp[cur] + MOD) % MOD) % MOD) % MOD;
}
else {
if (a[cur - n])
dp2[i][j] = dp2[i - 1][j - 1];
else
dp2[i][j] = dp2[i - 1][j];
}
tmp2 = (tmp2 + dp2[i][j]) % MOD;
}
dp2[i][0] = (tmp - tmp2 + MOD) % MOD;
dp2[i][i + 1] = 0;
}
dp[v] = 0;
for (int i = 1; i <= sz; i++)
dp[v] = (dp[v] + dp2[sz][i] * i % MOD) % MOD;
}
int count_ways(int l, int r) {
for (int i = l - n; i <= r - n; i++)
a[i] ^= 1;
getDP(0);
return dp[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
12 ms |
8016 KB |
Output is correct |
4 |
Correct |
12 ms |
8272 KB |
Output is correct |
5 |
Correct |
12 ms |
8344 KB |
Output is correct |
6 |
Correct |
12 ms |
8272 KB |
Output is correct |
7 |
Correct |
12 ms |
8272 KB |
Output is correct |
8 |
Correct |
14 ms |
8244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
12 ms |
8016 KB |
Output is correct |
4 |
Correct |
12 ms |
8272 KB |
Output is correct |
5 |
Correct |
12 ms |
8344 KB |
Output is correct |
6 |
Correct |
12 ms |
8272 KB |
Output is correct |
7 |
Correct |
12 ms |
8272 KB |
Output is correct |
8 |
Correct |
14 ms |
8244 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '172760924' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
3056 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
3056 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Runtime error |
11 ms |
3056 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
12 ms |
8016 KB |
Output is correct |
4 |
Correct |
12 ms |
8272 KB |
Output is correct |
5 |
Correct |
12 ms |
8344 KB |
Output is correct |
6 |
Correct |
12 ms |
8272 KB |
Output is correct |
7 |
Correct |
12 ms |
8272 KB |
Output is correct |
8 |
Correct |
14 ms |
8244 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '172760924' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
12 ms |
8016 KB |
Output is correct |
4 |
Correct |
12 ms |
8272 KB |
Output is correct |
5 |
Correct |
12 ms |
8344 KB |
Output is correct |
6 |
Correct |
12 ms |
8272 KB |
Output is correct |
7 |
Correct |
12 ms |
8272 KB |
Output is correct |
8 |
Correct |
14 ms |
8244 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '172760924' |
22 |
Halted |
0 ms |
0 KB |
- |