#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
#include "circuit.h"
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
ll const MAX_N=3e5+5;
ld const EPS=0.00000001;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(a) (int)a.size()
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int par[1005],state[1005],n,m,dp[1005][3];
vector<ll>g[1005];
void dfs(ll node,ll par){
if(node>=n){
if(state[node]==1){
dp[node][1]=1;
dp[node][0]=0;
}else {
dp[node][0]=1;
dp[node][1]=0;
}
return;
}
ll cnt=0,cnton=0,indx=-1,indx2=0;
for(auto it : g[node]){
if(it!=par){
dfs(it,node);
if(it>=n){
cnt++;
if(dp[it][1]==1){
cnton++;
}
}else {
if(indx!=-1){
indx2=it;
}
indx=it;
}
}
}
if(cnt==2){
dp[node][1]=cnton;
dp[node][0]=2-cnton;
}else if(cnt==1){
if(cnton==0){
dp[node][1]=dp[indx][1];
dp[node][0]=dp[indx][0]+dp[indx][0]+dp[indx][1];
}else {
dp[node][1]=dp[indx][0]+dp[indx][1]+dp[indx][0];
dp[node][0]=dp[indx][1];
}
}else if(cnt==0){
dp[node][0]=dp[indx][0]*dp[indx2][0]+dp[indx][0]*dp[indx2][1]+dp[indx][1]*dp[indx2][0]+dp[indx][0]*dp[indx2][0];
dp[node][1]=dp[indx][1]*dp[indx2][0]+dp[indx][0]*dp[indx2][1]+dp[indx][1]*dp[indx2][1]+dp[indx][1]*dp[indx2][1];
}
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n=N;
m=M;
for(ll i=0;i<n+m;i++)
{
par[i]=P[i];
if(i!=0){
g[par[i]].pb(i);
}
}
for(ll i=0;i<m;i++)
{
state[i+n]=A[i];
}
return;
}
int count_ways(int L, int R) {
ll l=L;
ll r=R;
for(ll i=l;i<=r;i++)
{
state[i]^=1;
}
dfs(0,-1);
return dp[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
2184 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
2184 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |