// failed/solution-prabowo-brute-binary.cpp
// O(Q(N + M))
#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;
}
for (int v : adj[u]) {
dfs(v);
}
int l = adj[u][0], r = adj[u][1];
int diff = (1LL * dp0[l] * dp1[r] + 1LL * dp1[l] * dp0[r]) % kMod;
dp0[u] = (2LL * dp0[l] * dp0[r] + diff) % kMod;
dp1[u] = (2LL * dp1[l] * dp1[r] + diff) % 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];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3026 ms |
4128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3026 ms |
4128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Execution timed out |
3026 ms |
4128 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |