// Be name khoda //
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const int mod = 1000002022;
const int maxn5 = 1e3 + 10;
int dp[maxn5][2], cnt[maxn5][2][maxn5], ty[maxn5];
vector <int> adj[maxn5];
void dfs(int v){
if(adj[v].empty()){
dp[v][1] = ty[v];
dp[v][0] = ty[v] ^ 1;
return;
}
cnt[v][1][0] = 1;
int x = 0;
for(auto u : adj[v]){
dfs(u);
for(int i = 0; i <= int(adj[v].size()); i++)
cnt[v][x][i] = (cnt[v][x ^ 1][i] * ll(dp[u][0]) % mod + (i ? cnt[v][x ^ 1][i - 1] * ll(dp[u][1]) % mod : 0)) % mod;
x ^= 1;
}
for(int i = 0; i <= int(adj[v].size()); i++){
dp[v][0] = (dp[v][0] + cnt[v][x ^ 1][i] * ll(int(adj[v].size()) - i)) % mod;
dp[v][1] = (dp[v][1] + cnt[v][x ^ 1][i] * ll(i)) % mod;
}
}
void init(int n, int m, std::vector<int> p, std::vector<int> a) {
for(int i = 1; i < n + m; i++)
adj[p[i]].pb(i);
for(int i = 0; i < m; i++)
ty[i + n] = a[i];
}
int count_ways(int l, int r) {
memset(dp, 0, sizeof dp);
memset(cnt, 0, sizeof cnt);
for(int i = l; i <= r; i++)
ty[i] ^= 1;
dfs(0);
return dp[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
4 ms |
8272 KB |
Output is correct |
3 |
Correct |
21 ms |
8272 KB |
Output is correct |
4 |
Correct |
23 ms |
8272 KB |
Output is correct |
5 |
Correct |
23 ms |
8272 KB |
Output is correct |
6 |
Correct |
23 ms |
8272 KB |
Output is correct |
7 |
Correct |
23 ms |
8272 KB |
Output is correct |
8 |
Correct |
23 ms |
8272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
5 ms |
8272 KB |
Output is correct |
3 |
Incorrect |
5 ms |
8272 KB |
1st lines differ - on the 1st token, expected: '655368480', found: '18160052' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
4 ms |
8272 KB |
Output is correct |
3 |
Correct |
21 ms |
8272 KB |
Output is correct |
4 |
Correct |
23 ms |
8272 KB |
Output is correct |
5 |
Correct |
23 ms |
8272 KB |
Output is correct |
6 |
Correct |
23 ms |
8272 KB |
Output is correct |
7 |
Correct |
23 ms |
8272 KB |
Output is correct |
8 |
Correct |
23 ms |
8272 KB |
Output is correct |
9 |
Correct |
4 ms |
8272 KB |
Output is correct |
10 |
Correct |
5 ms |
8272 KB |
Output is correct |
11 |
Incorrect |
5 ms |
8272 KB |
1st lines differ - on the 1st token, expected: '655368480', found: '18160052' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
20 ms |
19568 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
20 ms |
19568 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
5 ms |
8272 KB |
Output is correct |
3 |
Incorrect |
5 ms |
8272 KB |
1st lines differ - on the 1st token, expected: '655368480', found: '18160052' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
4 ms |
8272 KB |
Output is correct |
3 |
Correct |
21 ms |
8272 KB |
Output is correct |
4 |
Correct |
23 ms |
8272 KB |
Output is correct |
5 |
Correct |
23 ms |
8272 KB |
Output is correct |
6 |
Correct |
23 ms |
8272 KB |
Output is correct |
7 |
Correct |
23 ms |
8272 KB |
Output is correct |
8 |
Correct |
23 ms |
8272 KB |
Output is correct |
9 |
Correct |
4 ms |
8272 KB |
Output is correct |
10 |
Correct |
5 ms |
8272 KB |
Output is correct |
11 |
Incorrect |
5 ms |
8272 KB |
1st lines differ - on the 1st token, expected: '655368480', found: '18160052' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
4 ms |
8272 KB |
Output is correct |
3 |
Correct |
21 ms |
8272 KB |
Output is correct |
4 |
Correct |
23 ms |
8272 KB |
Output is correct |
5 |
Correct |
23 ms |
8272 KB |
Output is correct |
6 |
Correct |
23 ms |
8272 KB |
Output is correct |
7 |
Correct |
23 ms |
8272 KB |
Output is correct |
8 |
Correct |
23 ms |
8272 KB |
Output is correct |
9 |
Correct |
4 ms |
8272 KB |
Output is correct |
10 |
Correct |
5 ms |
8272 KB |
Output is correct |
11 |
Incorrect |
5 ms |
8272 KB |
1st lines differ - on the 1st token, expected: '655368480', found: '18160052' |
12 |
Halted |
0 ms |
0 KB |
- |