#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
int N,M;
vector<vector<int>> tree;
vector<int> state;
vector<int> poss;
int dfs(int i){
if(tree[i][0]>=N) return poss[i]=state[tree[i][0]]+state[tree[i][1]];
cout << i << "-i " << poss[i]<<"-possib \n";
int l=dfs(tree[i][0]),r=dfs(tree[i][1]);
int lv=poss[tree[i][0]], rv=poss[tree[i][1]];
poss[i]=(2*lv*rv)+(l*(2-r))+r*(2-l);
return max(l,1)+max(r,1);
}
void init(int n, int m, std::vector<int> P, std::vector<int> A) {
N=n; M=m;
tree.resize(N+M); state.resize(N+M);
for (int i = 1; i < N+M; i++) tree[P[i]].push_back(i);
for (int i = N; i < N+M; i++) state[i] = A[i-N];
}
int count_ways(int L, int R) {
poss.clear(); poss.resize(N+M,0);
for (int i = L; i <= R; i++) state[i] = 1-state[i];
int d=dfs(0);
return poss[0];
}
Compilation message
circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:32:7: warning: unused variable 'd' [-Wunused-variable]
32 | int d=dfs(0);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '509', found: '1' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Token parameter [name=secret] equals to "0-i", doesn't correspond to pattern "[0-9a-zA-Z]{1,64}" |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '509', found: '1' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
3980 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
3980 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Token parameter [name=secret] equals to "0-i", doesn't correspond to pattern "[0-9a-zA-Z]{1,64}" |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '509', found: '1' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '509', found: '1' |
4 |
Halted |
0 ms |
0 KB |
- |