# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
737933 | math_rabbit_1028 | Digital Circuit (IOI22_circuit) | C++17 | 3099 ms | 7856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "circuit.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int n, m, onoff[101010], par[202020];
vector<int> adj[202020];
const long long MOD = 1000002022;
long long cnt[202020], dp[202020];
void DFS(int v) {
if (v < n) cnt[v] = adj[v].size();
else cnt[v] = 1;
for (int i = 0; i < adj[v].size(); i++) {
int next = adj[v][i];
DFS(next);
cnt[v] = (cnt[v] * cnt[next]) % MOD;
}
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
for (int i = 0; i < n + m; i++) par[i] = P[i];
for (int i = 0; i < m; i++) onoff[i] = A[i];
for (int i = 1; i < n + m; i++) {
adj[par[i]].push_back(i);
}
DFS(0);
}
void solve(int v) {
if (v < n) dp[v] = 0;
else dp[v] = onoff[v - n];
for (int i = 0; i < adj[v].size(); i++) {
int next = adj[v][i];
solve(next);
long long t = dp[next];
for (int j = 0; j < adj[v].size(); j++) {
if (i != j) t = (t * cnt[adj[v][j]]) % MOD;
}
dp[v] = (dp[v] + t) % MOD;
}
}
int count_ways(int L, int R) {
for (int i = L; i <= R; i++) {
onoff[i - n] = 1 - onoff[i - n];
}
solve(0);
return dp[0];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |