#include "circuit.h"
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int MAX = 3e3;
const int MOD = 1000002022;
ll dp[2][MAX];
vector<ll> adj[MAX];
ll n, m;
void init(int N, int M, vector<int> P, vector<int> A) {
n = N, m = M;
memset(dp, 0, sizeof(dp));
for(int i = 0; i < N + M; i++){
if(P[i] == -1) continue;
adj[P[i]].push_back(i);
}
for(int i = 0; i < M; i++){
dp[A[i]][i + n] = 1;
}
}
void dfs(int u){
if(u >= n) return;
ll l = -1, r = -1;
for(auto v : adj[u]){
dfs(v);
if(l == -1) l = v;
else r = v;
}
if(l == -1 || r == -1) return;
dp[0][u] = (dp[0][l] * dp[1][r] % MOD + dp[1][l] * dp[0][r] % MOD + 2 * dp[0][l] * dp[0][r] % MOD) % MOD;
dp[1][u] = (dp[0][l] * dp[1][r] % MOD + dp[1][l] * dp[0][r] % MOD + 2 * dp[1][l] * dp[1][r] % MOD) % MOD;
}
int count_ways(int L, int R) {
for(int i = L; i <= R; i++){
dp[0][i] = 1 - dp[0][i];
dp[1][i] = 1 - dp[1][i];
}
dfs(0);
return dp[1][0];
}
# |
결과 |
실행 시간 |
메모리 |
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: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
2536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
2536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Runtime error |
11 ms |
2536 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |