// time_limit/solution-prabowo-brute.cpp
// O(Q(N + M)^2)
#include "circuit.h"
#include <algorithm>
#include <vector>
const int kMod = 1000002022;
std::vector<std::vector<int>> adj;
std::vector<int> dp0, dp1;
void dfs(int u) {
if (adj[u].empty()) {
return;
}
std::vector<int> dp = {1};
for (int v : adj[u]) {
dfs(v);
std::vector<int> prod0(dp.size()), prod1(dp.size());
for (int i = 0; i < static_cast<int>(dp.size()); ++i) {
prod0[i] = 1LL * dp[i] * dp0[v] % kMod;
prod1[i] = 1LL * dp[i] * dp1[v] % kMod;
}
dp[0] = prod0[0];
for (int i = 1; i < static_cast<int>(dp.size()); ++i) {
dp[i] = (prod0[i] + prod1[i - 1]) % kMod;
}
dp.push_back(prod1.back());
}
dp0[u] = 0;
for (int i = 0, sum = 0; i + 1 < static_cast<int>(dp.size()); ++i) {
sum = (sum + dp[i]) % kMod;
dp0[u] = (dp0[u] + sum) % kMod;
}
dp1[u] = 0;
for (int i = static_cast<int>(dp.size()) - 1, sum = 0; i >= 1; --i) {
sum = (sum + dp[i]) % kMod;
dp1[u] = (dp1[u] + sum) % kMod;
}
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
adj.resize(N + M);
for (int i = 1; i < N + M; ++i) {
adj[P[i]].push_back(i);
}
dp0.resize(N + M);
dp1.resize(N + M);
for (int i = N; i < N + M; ++i) {
if (A[i - N]) {
dp1[i] = 1;
} else {
dp0[i] = 1;
}
}
}
int count_ways(int L, int R) {
for (int i = L; i <= R; ++i) {
std::swap(dp0[i], dp1[i]);
}
dfs(0);
return dp1[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
15 ms |
404 KB |
Output is correct |
4 |
Correct |
15 ms |
416 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
21 ms |
336 KB |
Output is correct |
7 |
Correct |
15 ms |
400 KB |
Output is correct |
8 |
Correct |
17 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
15 ms |
404 KB |
Output is correct |
4 |
Correct |
15 ms |
416 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
21 ms |
336 KB |
Output is correct |
7 |
Correct |
15 ms |
400 KB |
Output is correct |
8 |
Correct |
17 ms |
408 KB |
Output is correct |
9 |
Correct |
1 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 |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
592 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
3 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
15 ms |
336 KB |
Output is correct |
30 |
Correct |
19 ms |
368 KB |
Output is correct |
31 |
Correct |
2 ms |
476 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
5 ms |
336 KB |
Output is correct |
36 |
Correct |
3 ms |
640 KB |
Output is correct |
37 |
Correct |
18 ms |
708 KB |
Output is correct |
38 |
Correct |
18 ms |
708 KB |
Output is correct |
39 |
Correct |
1 ms |
412 KB |
Output is correct |
40 |
Correct |
2 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3046 ms |
4140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3046 ms |
4140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
13 |
Execution timed out |
3046 ms |
4140 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
15 ms |
404 KB |
Output is correct |
4 |
Correct |
15 ms |
416 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
21 ms |
336 KB |
Output is correct |
7 |
Correct |
15 ms |
400 KB |
Output is correct |
8 |
Correct |
17 ms |
408 KB |
Output is correct |
9 |
Correct |
1 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 |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
592 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
3 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
15 ms |
336 KB |
Output is correct |
30 |
Correct |
19 ms |
368 KB |
Output is correct |
31 |
Correct |
2 ms |
476 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
5 ms |
336 KB |
Output is correct |
36 |
Correct |
3 ms |
640 KB |
Output is correct |
37 |
Correct |
18 ms |
708 KB |
Output is correct |
38 |
Correct |
18 ms |
708 KB |
Output is correct |
39 |
Correct |
1 ms |
412 KB |
Output is correct |
40 |
Correct |
2 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
236 KB |
Output is correct |
43 |
Execution timed out |
3093 ms |
592 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
15 ms |
404 KB |
Output is correct |
4 |
Correct |
15 ms |
416 KB |
Output is correct |
5 |
Correct |
18 ms |
332 KB |
Output is correct |
6 |
Correct |
21 ms |
336 KB |
Output is correct |
7 |
Correct |
15 ms |
400 KB |
Output is correct |
8 |
Correct |
17 ms |
408 KB |
Output is correct |
9 |
Correct |
1 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 |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
592 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
3 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
15 ms |
336 KB |
Output is correct |
30 |
Correct |
19 ms |
368 KB |
Output is correct |
31 |
Correct |
2 ms |
476 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
5 ms |
336 KB |
Output is correct |
36 |
Correct |
3 ms |
640 KB |
Output is correct |
37 |
Correct |
18 ms |
708 KB |
Output is correct |
38 |
Correct |
18 ms |
708 KB |
Output is correct |
39 |
Correct |
1 ms |
412 KB |
Output is correct |
40 |
Correct |
2 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
236 KB |
Output is correct |
43 |
Execution timed out |
3046 ms |
4140 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |