Submission #710511

#TimeUsernameProblemLanguageResultExecution timeMemory
710511myrcellaDigital Circuit (IOI22_circuit)C++17
18 / 100
16 ms2256 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000002022 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} #include "circuit.h" const int maxn = 2010; int a[maxn]; vector <int> edge[maxn]; void init(int N, int M, std::vector<int> P, std::vector<int> A) { rep(i,1,SZ(P)) { edge[P[i]].pb(i); } rep(i,0,SZ(A)) a[i+N]=A[i]; } pii solve(int u) { if (SZ(edge[u])==0) { if (a[u]==0) return {0,1}; else return {1,0}; } vector <pii> ans; for (int v:edge[u]) { ans.pb(solve(v)); } vector <int> f; f.pb(1); rep(i,0,SZ(ans)) { f.pb(1ll*f.back()*ans[i].fi%mod); for (int j = i;j>=0;j--) { f[j] = 1ll*f[j]*ans[i].se%mod; if (j>0) inc(f[j],1ll*f[j-1]*ans[i].fi%mod); } } pii ret = {0,0}; rep(i,0,SZ(f)) { inc(ret.se,1ll*f[i]*(SZ(f)-1-i)%mod); inc(ret.fi,1ll*f[i]*i%mod); } return ret; } int count_ways(int L, int R) { rep(i,L,R+1) a[i]^=1; return solve(0).fi; }
#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...