#include "circuit.h"
#include <bits/stdc++.h>
#define here cerr<<"==============================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define popb pop_back
#define all(x_) x_.begin(), x_.end()
using namespace std;
#define mod 1000002022
ll add(ll x,ll y){
x+=y;
x%=mod;
if(x<0) x+=mod;
return x;
}
ll mul(ll x,ll y){
x*=y;
x%=mod;
if(x<0) x+=mod;
return x;
}
#define maxn 1005
int n,m;
int par[maxn];
ll a[maxn];
int deg[maxn];
ll sub[maxn];
vector<int> g[maxn];
vector<int> v[maxn];
vector<int> topo;
bool cmp(int x,int y){
if(x<n) return 1;
if(y<n) return 0;
return 0;
}
void init(int N, int M, vector<int> P, vector<int> A) {
n = N;
m = M;
for(int i = 1;i<n+m;i++){
par[i+1] = P[i]+1;
g[i+1].pb(P[i]+1);
v[P[i]+1].pb(i+1);
deg[P[i]+1]++;
}
for(int i = n;i<n+m;i++) a[i+1] = A[i-n];
queue<int> q;
for(int i = 1;i<=n+m;i++) if(!deg[i]){
q.push(i);
}
for(ll i = 1;i<=n+m;i++) sub[i] = 1;
for(ll i = 1;i<=n;i++) sub[i] = deg[i];
while(q.size()){
int u = q.front();
q.pop();
if(u<=n) topo.pb(u);
for(int s : g[u]){
deg[s]--;
sub[s]=mul(sub[u],sub[u]);
if(!deg[s]) q.push(s);
}
}
for(ll i = 1;i<=n+m;i++) sort(all(v[i]),cmp);
/**
for(ll i = 1;i<=n+m;i++){
dbg(i);
for(ll x : v[i]) cerr<<x<< " ";
cerr<<endl;
}
**/
}
ll dp[maxn];
ll sum[maxn][maxn];
int count_ways(int L, int R){
L++; R++;
for(int i = L;i<=R;i++) a[i]^=1;
for(int i = n+1;i<=n+m;i++) dp[i] = 1;
for(int u : topo){
int sz = v[u].size();
ll cnt = 0;
while(sz>=1&&v[u][sz-1]>n){
cnt+=a[v[u][sz-1]];
sz--;
}
//dbg(u);
//dbg(cnt);
for(int j = 1;j<=sz;j++) cnt = mul(cnt,sub[v[u][j-1]]);
//dbg(cnt);
for(int i = 0;i<=sz;i++) for(int j = 1;j<=sz;j++) sum[i][j] = 0;
for(int i = 0;i<=sz;i++) sum[i][0] = 1;
dp[u] = cnt;
for(int k = 1;k<=sz;k++){
for(int j = 1;j<=sz;j++){
ll val = dp[v[u][j-1]];
sum[j][k] = add(sum[j-1][k],mul(sum[j-1][k-1],val));
}
dp[u] = add(dp[u],sum[sz][k]);
}
}
//cerr<<"dp: "<<endl;
//for(int i = 1;i<=n;i++) cerr<<dp[i]<< " ";
//cerr<<endl;
return dp[1];
}
/**
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
356 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 |
# |
결과 |
실행 시간 |
메모리 |
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: '126040765' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
356 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 |
0 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '126040765' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
1344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
1344 KB |
Execution killed with signal 11 |
2 |
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: '52130940', found: '126040765' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
356 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 |
0 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '126040765' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
356 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 |
0 ms |
336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '126040765' |
11 |
Halted |
0 ms |
0 KB |
- |