제출 #683002

#제출 시각아이디문제언어결과실행 시간메모리
683002sunwukong123디지털 회로 (IOI22_circuit)C++17
18 / 100
43 ms2300 KiB
#include "circuit.h" #include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i,s,e) for(int i = s; i <= (int)e; ++i) #define DEC(i,s,e) for(int i = s; i >= (int)e; --i) #define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL #define db(x) cerr << #x << "=" << x << "\n" #define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n" #define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n" #define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n" #define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{" << ite.f << ',' << ite.s << "} "; cerr << "\n" #define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n" #define reach cerr << "LINE: " << __LINE__ << "\n"; #else #define reach #define db(x) #define db2(x,y) #define db3(a,b,c) #define dbv(v) #define dbvp(v) #define dba(a,ss,ee) #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define f first #define s second #define g0(x) get<0>(x) #define g1(x) get<1>(x) #define g2(x) get<2>(x) #define g3(x) get<3>(x) typedef pair <int, int> pi; typedef tuple<int,int,int> ti3; typedef tuple<int,int,int,int> ti4; int rand(int a, int b) { return a + rng() % (b-a+1); } const int MOD = 1'000'002'022; const int inf = (int)1e9 + 500; const long long oo = (long long)1e18 + 500; template <typename T> bool chmax(T& a, const T b) { return a<b ? a = b, 1 : 0; } template <typename T> bool chmin(T& a, const T b) { return a>b ? a = b, 1 : 0; } const int MAXN = 2005; int dp[MAXN][2]; // number of ways of this guy, being on/off vector<int> V[MAXN]; int state[MAXN]; int n,m; int dpdp(int x, bool on) { db2(x,on); if(~dp[x][on]) return dp[x][on]; if(V[x].size() == 0) { //db(x); //db2(on,state[x-n]); if(on == state[x-n])return 1; else return 0; } int sz=V[x].size(); int c[2][sz+5]; memset(c,0,sizeof c); c[0][0]=1; // there is 1 way of having no children and having no turned on children FOR(i,1,sz){ int yes = dpdp(V[x][i-1], 1); // ways for this child to be on int no = dpdp(V[x][i-1], 0); // ways for this child to be off bool alt=i%2; memset(c[alt],0,sizeof c[alt]); FOR(j,0,i) { c[alt][j] = ((((j-1>=0)?c[1-alt][j-1]:0) * yes % MOD) + (c[1-alt][j] * no) % MOD)%MOD; } } bool lst=(sz)%2; if(on) { int ans = 0; FOR(i,1,sz) { // this is the capacity //for this to be okay, just make sure more than or equal i childs are turned on int t = 0; FOR(j,i,sz) t=(t+c[lst][j])%MOD; ans = (ans + t) % MOD; } db3(x,on,ans); return dp[x][on] = ans; } else { int ans = 0; FOR(i,1,sz) { // this is the capacity //for this to be okay, just make sure less than i childs are turned on int t = 0; FOR(j,0,i-1) t=(t+c[lst][j])%MOD; ans = (ans + t) % MOD; } db3(x,on,ans); return dp[x][on] = ans; } } void init(int32_t n, int32_t m, vector<int32_t> P, vector<int32_t> A) { ::n=n; ::m=m; FOR(i,1,n+m-1) { V[P[i]].pb(i); } FOR(i,0,m-1) { state[i]=A[i]; } } int32_t count_ways(int32_t L, int32_t R) { FOR(i,L,R) { state[i-n]=!state[i-n]; } memset(dp,-1,sizeof dp); int r= dpdp(0, 1); return r; }
#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...