#include "circuit.h"
#include "bits/stdc++.h"
using namespace std;
const int MAX_N = 2003;
int n, m;
int win[MAX_N];
int lose[MAX_N];
vector<int> a;
vector<int> g[MAX_N];
int dp[MAX_N][MAX_N];
vector<array<int, 2>> dps;
int knapsack(int ind, int k) {
if (ind == (int) dps.size()) {
return k == 0;
}
if (k < 0) {
return 0;
}
int& ret = dp[ind][k];
if (ret != -1) {
return ret;
}
ret = knapsack(ind + 1, k) * dps[ind][0] + knapsack(ind + 1, k - 1) * dps[ind][1];
return ret;
}
void dfs(int v) {
if (v >= n) {
lose[v] = (a[v - n] == 0);
win[v] = (a[v - n] == 1);
return;
}
for (int u : g[v]) {
dfs(u);
}
for (int u : g[v]) {
dps.push_back({lose[u], win[u]});
}
//memset(dp, -1, sizeof dp);
int ch_num = g[v].size();
for (int i = 0; i < ch_num; ++i) {
for (int j = 0; j <= ch_num; ++j) {
dp[i][j] = -1;
}
}
for (int k = 0; k <= ch_num; ++k) {
int x = knapsack(0, k);
win[v] += k * x;
lose[v] += (ch_num - k) * x;
}
dps.clear();
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
for (int i = 1; i < N + M; ++i) {
g[P[i]].push_back(i);
}
n = N;
m = M;
a = A;
}
int count_ways(int L, int R) {
for (int i = L; i <= R; ++i) {
a[i - n] ^= 1;
}
fill(win, win + n, 0);
fill(lose, lose + n, 0);
dfs(0);
return win[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
41 ms |
8040 KB |
Output is correct |
4 |
Correct |
42 ms |
8292 KB |
Output is correct |
5 |
Correct |
40 ms |
8272 KB |
Output is correct |
6 |
Correct |
41 ms |
8272 KB |
Output is correct |
7 |
Correct |
40 ms |
8272 KB |
Output is correct |
8 |
Correct |
48 ms |
8272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
41 ms |
8040 KB |
Output is correct |
4 |
Correct |
42 ms |
8292 KB |
Output is correct |
5 |
Correct |
40 ms |
8272 KB |
Output is correct |
6 |
Correct |
41 ms |
8272 KB |
Output is correct |
7 |
Correct |
40 ms |
8272 KB |
Output is correct |
8 |
Correct |
48 ms |
8272 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
2212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
2212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
41 ms |
8040 KB |
Output is correct |
4 |
Correct |
42 ms |
8292 KB |
Output is correct |
5 |
Correct |
40 ms |
8272 KB |
Output is correct |
6 |
Correct |
41 ms |
8272 KB |
Output is correct |
7 |
Correct |
40 ms |
8272 KB |
Output is correct |
8 |
Correct |
48 ms |
8272 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
41 ms |
8040 KB |
Output is correct |
4 |
Correct |
42 ms |
8292 KB |
Output is correct |
5 |
Correct |
40 ms |
8272 KB |
Output is correct |
6 |
Correct |
41 ms |
8272 KB |
Output is correct |
7 |
Correct |
40 ms |
8272 KB |
Output is correct |
8 |
Correct |
48 ms |
8272 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |