제출 #1236272

#제출 시각아이디문제언어결과실행 시간메모리
1236272AMel0nDigital Circuit (IOI22_circuit)C++20
7 / 100
3001 ms7452 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i,N) for(ll i = 0; i < N; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second #include "circuit.h" const ll MOD = 1000002022; int N, M; vector<vector<int>> C; vector<int> A; vector<vector<ll>> dp; void dfs(int n) { if (n >= N) { dp[n][A[n-N]] = 1; dp[n][!A[n-N]] = 0; return ; } for(int c: C[n]) { dfs(c); } ll one = (dp[C[n][0]][0] * dp[C[n][1]][1]) % MOD; ll two = (dp[C[n][0]][1] * dp[C[n][1]][0]) % MOD; ll three = 2 * (dp[C[n][0]][0] * dp[C[n][1]][0]) % MOD; dp[n][0] = (((one + two) % MOD) + three) % MOD; three = 2 * (dp[C[n][0]][1] * dp[C[n][1]][1]) % MOD; dp[n][1] = (((one + two) % MOD) + three) % MOD; } void init(int N, int M, std::vector<int> P, std::vector<int> A) { ::N = N; ::M = M; ::A = A; C.resize(N+M); dp.resize(N+M, vector<ll>(2)); for(int i = 1; i < N+M; i++) C[P[i]].push_back(i); } int count_ways(int L, int R) { for(int i = L-N; i <= R-N; i++) A[i] = !A[i]; dfs(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...