#define ll long long
#define pll pair<ll, ll>
#define MOD 1000002022
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
bool subFirst = false;
ll n = 0;
vector<ll> a(0);
vector<vector<ll>> adjlist(0);
void init(int N, int M, std::vector<int> P, std::vector<int> A)
{
n = N+M;
subFirst = (N <= 1000 && M <= 1000);
if(subFirst)
{
adjlist.assign(n, vector<ll> (0));
for(ll i = 1; i < n; i++)
{
adjlist[P[i]].push_back(i);
}
a.assign(n, 0);
for(ll i = N; i < n; i++)
{
a[i] = A[i-N];
}
}
}
pll dfs(int i) //On, off
{
if(adjlist[i].empty())
{
return {a[i], 1-a[i]};
}
ll c = adjlist[i].size();
ll all = c;
vector<ll> dp(c+1, 0); //Possibilities for being on
dp[0] = 1;
for(ll j : adjlist[i])
{
pll p = dfs(j);
all = (all * ((p.first+p.second)%MOD))%MOD;
vector<ll> postdp(c+1, 0);
for(ll k = 0; k <= c; k++)
{
postdp[k] = (dp[k]*p.second)%MOD;
if(k > 0)
{
postdp[k] = (postdp[k] + (dp[k-1]*p.first)%MOD)%MOD;
}
}
dp = postdp;
}
ll on = 0;
for(ll k = c; k > 0; k--)
{
on = (on+((dp[k]*k)%MOD))%MOD;
}
return {on, (all+MOD-on)%MOD};
}
int count_ways(int L, int R)
{
if(subFirst)
{
for(ll i = L; i <= R; i++)
{
a[i] = 1-a[i];
}
return dfs(0).first;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
21 ms |
364 KB |
Output is correct |
4 |
Correct |
21 ms |
360 KB |
Output is correct |
5 |
Correct |
18 ms |
336 KB |
Output is correct |
6 |
Correct |
18 ms |
336 KB |
Output is correct |
7 |
Correct |
18 ms |
336 KB |
Output is correct |
8 |
Correct |
18 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 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 |
1 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 |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
21 ms |
364 KB |
Output is correct |
4 |
Correct |
21 ms |
360 KB |
Output is correct |
5 |
Correct |
18 ms |
336 KB |
Output is correct |
6 |
Correct |
18 ms |
336 KB |
Output is correct |
7 |
Correct |
18 ms |
336 KB |
Output is correct |
8 |
Correct |
18 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 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 |
1 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 |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
352 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
416 KB |
Output is correct |
29 |
Correct |
18 ms |
336 KB |
Output is correct |
30 |
Correct |
19 ms |
368 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
592 KB |
Output is correct |
37 |
Correct |
18 ms |
592 KB |
Output is correct |
38 |
Correct |
22 ms |
720 KB |
Output is correct |
39 |
Correct |
1 ms |
356 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
451 ms |
976 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
451 ms |
976 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 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 |
1 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 |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Incorrect |
451 ms |
976 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '-1' |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
21 ms |
364 KB |
Output is correct |
4 |
Correct |
21 ms |
360 KB |
Output is correct |
5 |
Correct |
18 ms |
336 KB |
Output is correct |
6 |
Correct |
18 ms |
336 KB |
Output is correct |
7 |
Correct |
18 ms |
336 KB |
Output is correct |
8 |
Correct |
18 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 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 |
1 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 |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
352 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
416 KB |
Output is correct |
29 |
Correct |
18 ms |
336 KB |
Output is correct |
30 |
Correct |
19 ms |
368 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
592 KB |
Output is correct |
37 |
Correct |
18 ms |
592 KB |
Output is correct |
38 |
Correct |
22 ms |
720 KB |
Output is correct |
39 |
Correct |
1 ms |
356 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Incorrect |
492 ms |
336 KB |
1st lines differ - on the 1st token, expected: '196037954', found: '-1' |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
21 ms |
364 KB |
Output is correct |
4 |
Correct |
21 ms |
360 KB |
Output is correct |
5 |
Correct |
18 ms |
336 KB |
Output is correct |
6 |
Correct |
18 ms |
336 KB |
Output is correct |
7 |
Correct |
18 ms |
336 KB |
Output is correct |
8 |
Correct |
18 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 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 |
1 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 |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
352 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
416 KB |
Output is correct |
29 |
Correct |
18 ms |
336 KB |
Output is correct |
30 |
Correct |
19 ms |
368 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
592 KB |
Output is correct |
37 |
Correct |
18 ms |
592 KB |
Output is correct |
38 |
Correct |
22 ms |
720 KB |
Output is correct |
39 |
Correct |
1 ms |
356 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Incorrect |
451 ms |
976 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '-1' |
44 |
Halted |
0 ms |
0 KB |
- |