# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
652754 | Blagoj | Digital Circuit (IOI22_circuit) | C++17 | 10 ms | 2384 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 <bits/stdc++.h>
using namespace std;
vector<int> states;
vector<int> kids[1009];
int n, m;
long long mod = 1000002022;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
states = A;
n = N;
m = M;
for (int i = 1; i < P.size(); i++)
{
kids[P[i]].push_back(i);
}
}
long long dp[3000][2];
bool solved[3000];
int solve(int x)
{
solved[x] = true;
int k1 = kids[x][0], k2 = kids[x][1];
if (dp[k1][0] == -1 || dp[k1][1] == -1)
{
solve(k1);
}
if (dp[k2][0] == -1 || dp[k2][1] == -1)
{
solve(k2);
}
dp[x][0] = dp[k1][0] * dp[k2][1] + dp[k1][1] * dp[k2][0] + 2 * dp[k1][0] * dp[k2][0];
dp[x][1] = dp[k1][0] * dp[k2][1] + dp[k1][1] * dp[k2][0] + 2 * dp[k1][1] * dp[k2][1];
}
int count_ways(int L, int R) {
for (int i = L - n; i <= R - n; i++)
{
if (states[i] == 0)
{
states[i] = 1;
}
else
{
states[i] = 0;
}
}
if (n == 1)
{
int ans = 0;
for (int i = 1; i <= m; i++)
{
ans += states[i];
}
return ans;
}
for (int i = 0; i < n; i++)
{
dp[i][0] = dp[i][1] = -1;
}
for (int i = n; i < n + m; i++)
{
if (states[i] == 1)
{
dp[i][1] = 1;
dp[i][0] = 0;
}
else
{
dp[i][1] = 0;
dp[i][0] = 1;
}
}
memset(solved, 0, sizeof(solved));
for (int i = 0; i < n; i++)
{
if (!solved[i])
{
solve(i);
}
}
return dp[0][1];
}
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... |