# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
638241 | 2022-09-05T05:52:49 Z | jamezzz | Digital Circuit (IOI22_circuit) | C++17 | 3000 ms | 11404 KB |
#include "circuit.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define maxn 100005 #define mod 1000002022 int N,M,ways[maxn][2],pfx[maxn]; vector<int> A,AL[maxn]; vector<vector<ll>> memo[maxn]; void init(int _N,int _M,vector<int> P,vector<int> _A){ N=_N,M=_M; for(int i=0;i<N;++i)A.push_back(0); for(int i=N;i<N+M;++i){ A.push_back(_A[i-N]); ways[i][0]=(A[i]==0); ways[i][1]=(A[i]==1); } for(int i=0;i<N+M;++i){ AL[P[i]].push_back(i); } for(int i=0;i<N;++i){ memo[i].resize(AL[i].size()); for(int j=0;j<AL[i].size();++j){ memo[i][j].resize(AL[i].size()+1); } } } int dp(int u){ int n=AL[u].size(); for(int i=0;i<n;++i){ int v=AL[u][i]; if(v<N)dp(v); if(i==0){ for(int j=0;j<=n;++j){ memo[u][i][j]=0; } memo[u][i][0]=ways[v][0]; memo[u][i][1]=ways[v][1]; } else{ for(int j=0;j<=n;++j){ memo[u][i][j]=(memo[u][i-1][j]*ways[v][0])%mod; if(j!=0){ memo[u][i][j]+=(memo[u][i-1][j-1]*ways[v][1])%mod; memo[u][i][j]%=mod; } } } } ways[u][0]=ways[u][1]=0; for(int i=0;i<=n;++i){ if(i==0)pfx[i]=memo[u][n-1][i]; else pfx[i]=pfx[i-1]+memo[u][n-1][i]; pfx[i]%=mod; } for(int i=1;i<=n;++i){//if p=i ways[u][0]+=pfx[i-1]; ways[u][1]+=pfx[n]-pfx[i-1]+mod; ways[u][0]%=mod; ways[u][1]%=mod; } return ways[u][1]; } int count_ways(int L,int R){ for(int i=L;i<=R;++i){ A[i]=1-A[i]; swap(ways[i][0],ways[i][1]); } return dp(0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 7 ms | 9936 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 9916 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 7 ms | 9936 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3084 ms | 11404 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3084 ms | 11404 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 9916 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 7 ms | 9936 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 7 ms | 9936 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |