Submission #627311

#TimeUsernameProblemLanguageResultExecution timeMemory
627311happypotatoDigital Circuit (IOI22_circuit)C++17
0 / 100
1332 ms2097152 KiB
#include "circuit.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define ff first #define ss second #define pb push_back // global const int mxN = 1e5 + 1; const ll int MOD = 1'000'002'022; bool state[2 * mxN]; ll int dp[2 * mxN][2]; int n, m; // dp[i][j] = no of ways to light up at pos i with constraint c void dfs(int u); void init(int N, int M, vector<int> P, vector<int> A) { // if (!(N <= 1000 && M <= 1000)) throw runtime_error("idk"); n = N; m = M; for (int i = 0; i < M; i++) { state[i + N] = (A[i] == 1); } dfs(0); } void update(int u) { dp[u][0] = dp[u][1] = 0; dp[u][0] += (dp[u * 2][0] * dp[u * 2 + 1][0] % MOD) * 2 % MOD; dp[u][0] += (dp[u * 2][0] * dp[u * 2 + 1][1] % MOD); dp[u][1] += (dp[u * 2][0] * dp[u * 2 + 1][1] % MOD); dp[u][0] += (dp[u * 2][1] * dp[u * 2 + 1][0] % MOD); dp[u][1] += (dp[u * 2][1] * dp[u * 2 + 1][0] % MOD); dp[u][1] += (dp[u * 2][1] * dp[u * 2 + 1][1] % MOD) * 2 % MOD; dp[u][0] %= MOD; dp[u][1] %= MOD; } void dfs(int u) { if (u >= n) { dp[u][0] = (state[u] == 0); dp[u][1] = (state[u] == 1); return; } dfs(u * 2); dfs(u * 2 + 1); update(u); } int count_ways(int L, int R) { int u = L; swap(dp[u][0], dp[u][1]); while (u) { u = (u - 1) / 2; update(u); } 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...