Submission #1074863

#TimeUsernameProblemLanguageResultExecution timeMemory
1074863c2zi6디지털 회로 (IOI22_circuit)C++17
18 / 100
3060 ms8636 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "circuit.h" const ll MOD = 1000002022; bool test6; int n, sz; VVI gp; VI val; VL dpa; // sev VL dpb; // spitak VI depth; VL contr; void dfs2(int u = 0) { for (int v : gp[u]) { depth[v] = depth[u]+1; dfs2(v); } } void init(int N, int M, VI P, VI A) { n = N + M; sz = M; gp = VVI(n); rep(u, n) if (u) gp[P[u]].pb(u); val = VI(n); rep(u, M) val[u+N] = A[u]; depth = VI(n); test6 = true; rep(u, n) if (gp[u].size() != 2) test6 = false; if (test6) { dfs2(); contr = VL(n); VL twopow(n+1); twopow[0] = 1; replr(i, 1, n) twopow[i] = twopow[i-1]*2 % MOD; rep(u, n) contr[u] = twopow[N - depth[u]]; } } VL subsets(VL& a, VL& b) { int n = a.size(); VVL dp(n+1, VL(n+1)); dp[0][0] = 1; replr(j, 1, n) dp[j][0] = dp[j-1][0]*b[j-1]%MOD; replr(i, 1, n) replr(j, 1, n) { dp[i][j] = dp[i-1][j-1]*a[i-1]%MOD + dp[i-1][j]*b[i-1]%MOD; dp[i][j] %= MOD; } VL ret(n+1); replr(i, 0, n) ret[i] = dp[n][i]; return ret; } void dfs1(int u = 0) { for (int v : gp[u]) dfs1(v); dpa[u] = dpb[u] = 0; if (gp[u].size() == 0) { if (val[u]) dpa[u] = 1; else dpb[u] = 1; return; } VL a, b; for (int v : gp[u]) { a.pb(dpa[v]); b.pb(dpb[v]); } int c = gp[u].size(); VL s = subsets(a, b); replr(i, 0, c) { dpa[u] += s[i]*i % MOD; dpa[u] %= MOD; dpb[u] += s[i]*(c-i) % MOD; dpb[u] %= MOD; } } int count_ways(int L, int R) { if (test6) { replr(i, L, R) val[i] = !val[i]; ll ans = 0; rep(i, n) if (val[i]) ans += contr[i]; return ans; } else { replr(i, L, R) val[i] = !val[i]; dpa = dpb = VL(n); dfs1(); return dpa[0]; } return -1488; }
#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...