Submission #720396

#TimeUsernameProblemLanguageResultExecution timeMemory
720396ismayilDigital Circuit (IOI22_circuit)C++17
9 / 100
10 ms2472 KiB
#include "circuit.h" #include <bits/stdc++.h> #define ll long long #define endl '\n' using namespace std; const int MAX = 3e3; const int MOD = 1000002022; ll dp[2][MAX]; vector<int> adj[MAX]; int n, m; void init(int N, int M, vector<int> P, vector<int> A) { n = N, m = M; memset(dp, 0, sizeof(dp)); for(int i = 0; i < N + M; i++){ if(P[i] == -1) continue; adj[P[i]].push_back(i); } for(int i = 0; i < M; i++){ dp[A[i]][i + n] = 1; } } void dfs(int u){ if(u >= n) return; int l = -1, r = -1; for(auto v : adj[u]){ dfs(v); if(l == -1) l = v; else r = v; } dp[0][u] = (dp[0][l] * dp[1][r] % MOD + dp[1][l] * dp[0][r] % MOD + 2 * dp[0][l] * dp[0][r] % MOD) % MOD; dp[1][u] = (dp[0][l] * dp[1][r] % MOD + dp[1][l] * dp[0][r] % MOD + 2 * dp[1][l] * dp[1][r] % MOD) % MOD; } int count_ways(int L, int R) { for(int i = L; i <= R; i++){ dp[0][i] = 1 - dp[0][i]; dp[1][i] = 1 - dp[1][i]; } if(n == 1){ int cnt = 0; for(int i = n; i < n + m; i++){ cnt += dp[1][i]; } return cnt; } dfs(0); return dp[1][0]; }
#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...