#include "circuit.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz size()
#define F first
#define S second
const int W = 2003;
vector<int> a;
vector<ll> v[W];
ll dp[W][W];
pair<ll,ll> dpp[W];
ll mod = 1000002022, n , m;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
a = A;
n = N, m = M;
for(int i = 1; i < N+M; i++)
{
v[P[i]].push_back(i);
}
}
void go(ll &x)
{
x = x%mod;
}
void dfs(ll x)
{
if(v[x].sz==0)
{
if(a[x-n]) dpp[x].F = 1;
else dpp[x].S = 1;
return;
}
dp[x][0] = 1;
for(int i = 0; i < v[x].sz; i++)
{
dfs(v[x][i]);
for(int j = i+1; j>=0; j--)
{
dp[x][j] = dp[x][j]*dpp[v[x][i]].S;
if(j>0) dp[x][j] += dp[x][j-1]*dpp[v[x][i]].F;
go(dp[x][j]);
}
}
ll sum = dp[x][0];
ll all = 0;
for(int i = 0; i <= v[x].sz; i++) all+= dp[x][i]; all%=mod;
for(int i = 1; i <= v[x].sz; i++)
{
dpp[x].S += sum;
dpp[x].F += (all-sum+mod)%mod;
go(dpp[x].F); go(dpp[x].S);
sum = (sum+dp[x][i])%mod;
}
}
int count_ways(int L, int R) {
for(int i = L; i <= R; i++) a[i-n] = !a[i-n];
for(int i = 0; i < n + m; i++) {dpp[i] = {0,0}; for(int j = 0; j <= v[i].sz; j++) dp[i][j] = 0; }
dfs(0);
// for(int i = 0; i < n + m; i++)
// cout << dpp[i].F << " " << dpp[i].S << endl; cout << endl;
//for(int i = 0; i < n+m; i++) { for(int j = 0; j <=v[i].sz; j++) cout << dp[i][j] << " "; cout << endl;}
return dpp[0].F;
return 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... |