Submission #643474

#TimeUsernameProblemLanguageResultExecution timeMemory
643474VanillaDigital Circuit (IOI22_circuit)C++17
0 / 100
16 ms2128 KiB
#include <bits/stdc++.h> #include "circuit.h" typedef long long int64; using namespace std; const int64 mod = 1000002022; const int maxn = 2e3 + 2; vector <int> ad [maxn]; int64 dp[maxn][2]; int n,m; void init(int N, int M, vector<int> P, vector<int> A) { n = N, m = M; for (int i = 1; i < N + M; i++){ ad[P[i]].push_back(i); } for (int i = 0; i < M; i++){ dp[N+i][A[i]] = 1; } } void build (int x) { if (x > n) return; int l = ad[x][0], r = ad[x][1]; build(l); build(r); dp[x][0] = ((dp[l][0] * dp[r][0] * 2 % mod) + (dp[l][0] * dp[r][1] % mod) + (dp[l][1] * dp[r][0] % mod)) % mod; dp[x][1] = ((dp[l][1] * dp[r][1] * 2 % mod) + (dp[l][0] * dp[r][1] % mod) + (dp[l][1] * dp[r][0] % mod)) % mod; } int count_ways(int L, int R) { for (int i = L; i <= R; i++){ swap(dp[n+i][0], dp[n+i][1]); } build(0); return dp[0][1]; }
#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...