Submission #912646

#TimeUsernameProblemLanguageResultExecution timeMemory
912646biankDigital Circuit (IOI22_circuit)C++17
0 / 100
13 ms2548 KiB
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int,int> ii; #define ALL(x) x.begin(),x.end() #define SIZE(x) (int)x.size() #define forsn(i,s,n) for(int i=int(s);i<int(n);i++) #define forn(i,n) for(int i=0;i<int(n);i++) #define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--) #define dforn(i,n) for(int i=int(n)-1;i>=0;i--) #define fst first #define snd second #define pb push_back const int MAXN = 2000; const int MOD = 1e9+2022; vi s, adj[MAXN]; int n, m; void init(int N, int M, vi P, vi A) { s=A, n=N, m=M; forsn(i,1,n+m) adj[P[i]].pb(i); } int mul(int x, int y) { return (long long) x * y % MOD; } void add(int &x, int v) { x+=v; if(x>=MOD) x-=MOD; } ii dfs(int u) { int c=SIZE(adj[u]); if(!c) return {!s[u-n], s[u-n]}; vi ways(c+1,0); ways[0] = 1; forn(i,c) { ii child=dfs(adj[u][i]); dforn(j,i+1) { ways[j] = mul(ways[j],child.fst); if(j) add(ways[j],mul(ways[j-1],child.snd)); } } ii ans = {0,0}; forsn(i,1,c+1) { forn(j,i) add(ans.fst, ways[j]); forsn(j,i,c+1) add(ans.snd, ways[j]); } return ans; } int count_ways(int L, int R) { forsn(i,L,R+1) { s[i-n]^=1; } return int(dfs(0).snd); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...