# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870407 | Nonoze | 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 "circuit.h"
#include "stub.cpp"
#include <bits/stdc++.h>
using namespace std;
const long long MOD= 1000002022;
vector<int> a;
vector<int> adj[100005];
int n, m;
pair<long long, long long> dfs(int s) {
if (s>=n) {
return {a[s-n], a[s-n]^1};
}
long long comp=0;
vector<long long> dp(adj[s].size()+1, 0);
dp[0]=1;
for (auto u: adj[s]) {
auto act=dfs(u);
for (int i=dp.size()-1; i>=0; i--) {
dp[i]*=act.second;
if (i>0) {
dp[i]+=dp[i-1]*act.first;
}
dp[i]%=MOD;
}
}
for (int i=1; i<(int)dp.size()-1; i++) {
comp+=dp[i]*i;
}
comp=(comp+10*MOD)%MOD;
long long sz=adj[s].size();
return {
(comp+(dp.back()*sz)%MOD)%MOD,
(comp+(dp[0]*sz)%MOD)%MOD
};
}
void init(int N, int M, vector<int> p, vector<int> aa) {
a=aa;
n=N, m=M;
for (int i=1; i<n+m; i++) {
adj[p[i]].push_back(i);
}
}
int count_ways(int L, int R) {
for (int i=L; i<=R; i++) {
a[i-n]^=1;
}
return dfs(0).first;
}