제출 #1080675

#제출 시각아이디문제언어결과실행 시간메모리
1080675asdasdqwer디지털 회로 (IOI22_circuit)C++17
18 / 100
3053 ms4932 KiB
#include "circuit.h" #include <bits/stdc++.h> using namespace std; const int MOD = 1000002022; vector<vector<int>> child; vector<long long> dp1, dp2; int n,m; vector<int> a; void calc(int node = 0) { // cout << node << endl; if (child[node].size() == 0) { dp1[node] = a[node-n]; dp2[node] = 1-a[node-n]; return; } vector<long long> dp3(child[node].size()+1, 0); dp3[0]=1; for (int &x:child[node]){ calc(x); for (int i=(int)dp3.size()-1;i>0;i--) { dp3[i] = (dp3[i] + dp1[x] * dp3[i-1]) % MOD; dp3[i-1] = (dp3[i-1] * dp2[x]) % MOD; } // for (auto &x:dp3) { // cout<<x<<" "; // } // cout<<endl; } // cout << "node " << node << "\n"; // cout << "end " << node << endl; dp1[node] = dp2[node] = 0; for (int i=0;i<(int)dp3.size();i++) { dp1[node] = (dp1[node] + dp3[i] * i) % MOD; dp2[node] = (dp2[node] + dp3[i] * ((int)dp3.size() - i - 1)) % MOD; } // cout << dp1[node] << " " << dp2[node] << endl; // cout << endl; } void init(int N, int M, std::vector<int> P, std::vector<int> A) { n = N;m=M; a = A; child.resize(n+m); for (int i=1;i<N+M;i++) { child[P[i]].push_back(i); } dp1.resize(n+m); dp2.resize(n+m); } int count_ways(int L, int R) { // cout << "first print a" << endl; for (int i=L-n;i<=R-n;i++) { a[i] = 1-a[i]; } // for (int i=0;i<m;i++) { // cout<<a[i]<<" "; // } // cout<<"\n"; calc(); return dp1[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...