제출 #1058517

#제출 시각아이디문제언어결과실행 시간메모리
1058517SalihSahinDigital Circuit (IOI22_circuit)C++17
2 / 100
7 ms2392 KiB
#include<bits/stdc++.h> #define pb push_back using namespace std; #include "circuit.h" const int M = 2000; vector<int> state(M); vector<int> ch[2 * M]; int n; pair<int, int> dfs(int node){ // {kac sekilde 0, kac sekilde 1} if(node >= n){ if(state[node - n]) return {0, 1}; else return {1, 0}; } vector<pair<int, int> > sub; int c = ch[node].size(); for(auto itr: ch[node]){ sub.pb(dfs(itr)); } vector<int> dp(c+1), ndp(c+1); dp[0] = 1; for(auto itr: sub){ for(int i = 0; i <= c; i++){ ndp[i] = 0; ndp[i] += dp[i] * itr.first; if(i) ndp[i] += dp[i-1] * itr.second; } dp = ndp; } pair<int, int> val; for(int i = 1; i <= c; i++){ for(int j = 0; j <= c; j++){ if(i > j) val.first += dp[j]; else val.second += dp[j]; } } return val; } void init(int N, int M, std::vector<int> P, std::vector<int> A) { n = N; for(int i = 1; i < N + M; i++){ ch[P[i]].pb(i); } for(int i = 0; i < M; i++) state[i] = A[i]; return; } int count_ways(int L, int R) { L -= n; R -= n; for(int i = L; i <= R; i++){ state[i] ^= 1; } pair<int, int> ans = dfs(0); return ans.second; } /* int main() { int N, M, Q; assert(3 == scanf("%d %d %d", &N, &M, &Q)); std::vector<int> P(N + M), A(M); for (int i = 0; i < N + M; ++i) { assert(1 == scanf("%d", &P[i])); } for (int j = 0; j < M; ++j) { assert(1 == scanf("%d", &A[j])); } init(N, M, P, A); for (int i = 0; i < Q; ++i) { int L, R; assert(2 == scanf("%d %d", &L, &R)); printf("%d\n", count_ways(L, R)); } return 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...