# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
910872 | tnun | Digital Circuit (IOI22_circuit) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int N,M;
vector<int> P;
vector<int> A;
ll int mod=1000002022;
vector<int> adj[200050];
ll int one[200050]={0};
ll int zer[200050]={0};
void dfs(int node){
if(node>=N){
if(A[node-N]==1){
one[node]=1;
zer[node]=0;
}else{
one[node]=0;
zer[node]=1;
}
return;
}
for(int i=0;i<adj[node].size();i++){
dfs(adj[node][i]);
}
ll int all=1;
for(int i=0;i<adj[node].size();i++){
all*=(one[adj[node][i]]+zer[adj[node[i]]]);
all=all%mod;
}
for(int i=0;i<adj[node].size();i++){
one[node]+=(one[adj[node][i]])*all/(one[adj[node][i]]+zer[adj[node][i]]);
one[node]=one[node]%mod;
}
zer[node]=all-one[node];
}
int count_ways(int l,int r){
memset(one, 0, sizeof(one));
memset(zer, 0, sizeof(zer));
int visited[N+M+1]={0};
for(int i=l-1;i<r;i++){
A[i]=(A[i]+1)%2;
}
dfs(0);
return one[0];
}
void init(int N,int M, vector<int> P,vector<int> A){
for(int i=1;i<N+M;i++){
adj[P[i]].pb(i);
}
}