#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+2022;
const ll N=2007;
ll n,m,k;
vector<int>g[N];
vector<int>p;
vector<int>a;
ll tot[N];
ll dp[N];
void calc_tot(int v){
if(!g[v].size()){tot[v]=1;return;}
tot[v]=g[v].size();
for(int to:g[v]){
calc_tot(to);
tot[v]*=tot[to];
tot[v]%=MOD;
}
}
void calc_dp(int v){
if(!g[v].size()){
dp[v]=a[v];
return;
}
for(int to:g[v])calc_dp(to);
vector<int>d;
ll cur=1;
for(int to:g[v]){
d.push_back(cur);
cur*=tot[to];
cur%=MOD;
}
cur=1;
ll sum=0;
// cout<<"DDDDD\n";
for(int i=g[v].size()-1;i>=0;i--){
// cout<<g[v][i]<<": "<<d[i]<<" ";
d[i]*=cur;
d[i]%=MOD;
// cout<<d[i]<<" ";
d[i]*=dp[g[v][i]];
d[i]%=MOD;
// cout<<d[i]<<endl;
sum+=d[i];
sum%=MOD;
cur*=tot[g[v][i]];
cur%=MOD;
}
dp[v]=sum;
}
void init(int NN, int MM, vector<int> P, vector<int> A) {
n=NN;
m=MM;
for(int v=1;v<n+m;v++){
g[P[v]].push_back(v);
// g[v].push_back(P[v]);
}
p=P;
a.resize(n+m,0);
for(int i=0;i<m;i++){
a[i+n]=A[i];
}
calc_tot(0);
// for(int v=0;v<n+m;v++){
// cout<<v<<": "<<tot[v]<<endl;
// }
}
int count_ways(int L, int R) {
for(int i=L;i<=R;i++){
a[i]=!a[i];
}
calc_dp(0);
// for(int v=0;v<n+m;v++){
// cout<<v<<": "<<dp[v]<<", "<<a[v]<<endl;
// }
return dp[0];
}
# |
Verdict |
Execution time |
Memory |
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 |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-222605210' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-222605210' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
2128 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
2128 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-222605210' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-222605210' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-222605210' |
11 |
Halted |
0 ms |
0 KB |
- |