This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "circuit.h"
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int MAX = 3e3;
ll dp[2][MAX];
vector<ll> adj[MAX];
ll n, m;
void init(int N, int M, vector<int> P, vector<int> A) {
n = N, m = M;
for(int i = 0; i < N + M; i++){
if(P[i] == -1) continue;
adj[P[i]].push_back(i);
}
for(int i = 0; i < M; i++){
dp[A[i]][i + n] = 1;
}
}
void dfs(int u){
if(u >= n) return;
ll l = -1, r = -1;
for(auto v : adj[u]){
dfs(v);
if(l == -1) l = v;
else r = v;
}
dp[0][u] = dp[0][l] * dp[1][r] + dp[1][l] * dp[0][r] + 2 * dp[0][l] * dp[0][r];
dp[1][u] = dp[0][l] * dp[1][r] + dp[1][l] * dp[0][r] + 2 * dp[1][l] * dp[1][r];
}
int count_ways(int L, int R) {
for(int i = L; i <= R; i++){
dp[0][i] = 1 - dp[0][i];
dp[1][i] = 1 - dp[1][i];
}
dfs(0);
return dp[1][0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |