#include "circuit.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
typedef long long llong;
const int MAXN = 200000 + 10;
const int MOD = 1000002022;
const int INF = 1e9;
int n, m;
llong w[MAXN];
llong b[MAXN];
llong pw[MAXN];
std::vector <int> g[MAXN];
void initDFS(int node)
{
if (g[node].empty())
{
pw[node] = 1;
return;
}
pw[node] = g[node].size();
for (const int &i : g[node])
{
initDFS(i);
pw[node] *= pw[i];
pw[node] %= MOD;
}
}
void init(int N, int M, std::vector <int> P, std::vector <int> A)
{
n = N;
m = M;
for (int i = 1 ; i < n + m ; ++i)
{
g[P[i] + 1].push_back(i + 1);
}
for (int i = n + 1 ; i <= n + m ; ++i)
{
if (A[i - n - 1] == 0)
{
w[i] = 1;
b[i] = 0;
} else
{
b[i] = 1;
w[i] = 0;
}
}
initDFS(1);
}
void dfs(int node)
{
if (g[node].empty())
{
return;
}
b[node] = 0;
for (const int &i : g[node])
{
dfs(i);
b[node] += 1LL * ((pw[node] / pw[i]) / g[node].size()) * b[i];
b[node] %= MOD;
}
w[node] = pw[node] - b[node];
if (w[node] < 0) w[node] += MOD;
}
int count_ways(int L, int R)
{
L++; R++;
for (int i = L ; i <= R ; ++i)
{
std::swap(b[i], w[i]);
}
dfs(1);
return b[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
4 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3072 ms |
7928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3072 ms |
7928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
4 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
4 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |