#include "circuit.h"
#include <vector>
#include <iostream>
using namespace std;
const int MAXN = 100000;
const int MAXM = 100000;
int N, M;
//int P[MAXN+MAXM];
int A[MAXN+MAXM];
vector<int> adj[MAXN];
const int MOD = 1000002022;
int DP[MAXN + MAXM][2];
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
::N = N;
::M = M;
for (int i = 0; i < N+M; ++i) {
// ::P[i] = P[i];
int p = P[i];
adj[p].push_back(i);
}
for (int i = 0; i < M; ++i)
::A[i] = A[i];
for (int i = N; i < N+M; ++i)
DP[i][ A[i-N] ] = 1;
// cerr << "init finished" << endl;
}
int count_ways(int L, int R) {
// cerr << "L: " << L << " R:" << R << endl;
for (int i = L; i <= R; ++i) {
A[i-N] ^= 1;
if (A[i-N]) {
DP[i][0] = 0;
DP[i][1] = 1;
}
else {
DP[i][0] = 1;
DP[i][1] = 0;
}
}
/*
for (int i = 0; i < M; ++i)
cerr << A[i] << ' ';
cerr << endl;
*/
for (int u = N-1; u >= 0; --u) {
const int NC = adj[u].size();
vector<int> DPt(NC+1, 0);
DPt[0] = 1;
for (int j = 0; j < (int) adj[u].size(); ++j) {
int v = adj[u][j];
for (int ones = j+1; ones > 0; --ones) {
DPt[ones] = (DPt[ones ] * 1LL * DP[v][0] +
DPt[ones-1] * 1LL * DP[v][1]) % MOD;
}
DPt[0] = (DPt[0] * 1LL * DP[v][0]) % MOD;
}
DP[u][0] = DP[u][1] = 0;
for (int ones = 0; ones <= NC; ++ones) {
DP[u][0] = (DP[u][0] + DPt[ones] * 1LL * (NC - ones)) % MOD;
DP[u][1] = (DP[u][1] + DPt[ones] * 1LL * ones) % MOD;
}
}
// for (int i = 0; i < N+M; ++i)
// cerr << i << ": " << DP[i][0] << ' ' << DP[i][1] << endl;
return DP[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
6 ms |
2640 KB |
Output is correct |
4 |
Correct |
6 ms |
2640 KB |
Output is correct |
5 |
Correct |
7 ms |
2696 KB |
Output is correct |
6 |
Correct |
8 ms |
2640 KB |
Output is correct |
7 |
Correct |
7 ms |
2696 KB |
Output is correct |
8 |
Correct |
6 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2584 KB |
Output is correct |
4 |
Correct |
2 ms |
2592 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
3 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
3 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
6 ms |
2640 KB |
Output is correct |
4 |
Correct |
6 ms |
2640 KB |
Output is correct |
5 |
Correct |
7 ms |
2696 KB |
Output is correct |
6 |
Correct |
8 ms |
2640 KB |
Output is correct |
7 |
Correct |
7 ms |
2696 KB |
Output is correct |
8 |
Correct |
6 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2584 KB |
Output is correct |
12 |
Correct |
2 ms |
2592 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
3 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
3 ms |
2640 KB |
Output is correct |
21 |
Correct |
3 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
2 ms |
2640 KB |
Output is correct |
27 |
Correct |
3 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
7 ms |
2700 KB |
Output is correct |
30 |
Correct |
7 ms |
2692 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
3 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
3 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2640 KB |
Output is correct |
37 |
Correct |
7 ms |
2640 KB |
Output is correct |
38 |
Correct |
7 ms |
2744 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3091 ms |
4852 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3091 ms |
4852 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2584 KB |
Output is correct |
4 |
Correct |
2 ms |
2592 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
3 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
3 ms |
2640 KB |
Output is correct |
13 |
Execution timed out |
3091 ms |
4852 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
6 ms |
2640 KB |
Output is correct |
4 |
Correct |
6 ms |
2640 KB |
Output is correct |
5 |
Correct |
7 ms |
2696 KB |
Output is correct |
6 |
Correct |
8 ms |
2640 KB |
Output is correct |
7 |
Correct |
7 ms |
2696 KB |
Output is correct |
8 |
Correct |
6 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2584 KB |
Output is correct |
12 |
Correct |
2 ms |
2592 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
3 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
3 ms |
2640 KB |
Output is correct |
21 |
Correct |
3 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
2 ms |
2640 KB |
Output is correct |
27 |
Correct |
3 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
7 ms |
2700 KB |
Output is correct |
30 |
Correct |
7 ms |
2692 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
3 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
3 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2640 KB |
Output is correct |
37 |
Correct |
7 ms |
2640 KB |
Output is correct |
38 |
Correct |
7 ms |
2744 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Execution timed out |
3072 ms |
2768 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
6 ms |
2640 KB |
Output is correct |
4 |
Correct |
6 ms |
2640 KB |
Output is correct |
5 |
Correct |
7 ms |
2696 KB |
Output is correct |
6 |
Correct |
8 ms |
2640 KB |
Output is correct |
7 |
Correct |
7 ms |
2696 KB |
Output is correct |
8 |
Correct |
6 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2584 KB |
Output is correct |
12 |
Correct |
2 ms |
2592 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
3 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
3 ms |
2640 KB |
Output is correct |
21 |
Correct |
3 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
2 ms |
2640 KB |
Output is correct |
27 |
Correct |
3 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
7 ms |
2700 KB |
Output is correct |
30 |
Correct |
7 ms |
2692 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
3 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
3 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2640 KB |
Output is correct |
37 |
Correct |
7 ms |
2640 KB |
Output is correct |
38 |
Correct |
7 ms |
2744 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Execution timed out |
3091 ms |
4852 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |