#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#include "circuit.h"
const int M = 2000;
int mod = 10121101010;
int add(int a, int b){
return ((a%mod) + (b%mod))%mod;
};
int mul(int a, int b){
return ((a%mod) * (b%mod))%mod;
};
vector<int> state(M);
vector<int> ch[2 * M];
int n;
pair<int, int> dfs(int node){ // {kac sekilde 0, kac sekilde 1}
if(node >= n){
if(state[node - n]) return {0, 1};
else return {1, 0};
}
vector<pair<int, int> > sub;
int c = ch[node].size();
for(auto itr: ch[node]){
sub.pb(dfs(itr));
}
vector<int> dp(c+1), ndp(c+1);
dp[0] = 1;
for(auto itr: sub){
for(int i = 0; i <= c; i++){
ndp[i] = 0;
ndp[i] = add(ndp[i], mul(dp[i], itr.first));
if(i) ndp[i] = add(ndp[i], mul(dp[i-1], itr.second));
}
dp = ndp;
}
pair<int, int> val;
for(int i = 1; i <= c; i++){
for(int j = 0; j <= c; j++){
if(i > j) val.first = add(val.first, dp[j]);
else val.second = add(val.second, dp[j]);
}
}
return val;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
for(int i = 1; i < N + M; i++){
ch[P[i]].pb(i);
}
for(int i = 0; i < M; i++) state[i] = A[i];
return;
}
int count_ways(int L, int R) {
L -= n;
R -= n;
for(int i = L; i <= R; i++){
state[i] ^= 1;
}
pair<int, int> ans = dfs(0);
return ans.second;
}
Compilation message
circuit.cpp:8:11: warning: overflow in conversion from 'long int' to 'int' changes value from '10121101010' to '1531166418' [-Woverflow]
8 | int mod = 10121101010;
| ^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
92 ms |
564 KB |
Output is correct |
4 |
Correct |
97 ms |
344 KB |
Output is correct |
5 |
Correct |
97 ms |
344 KB |
Output is correct |
6 |
Correct |
98 ms |
344 KB |
Output is correct |
7 |
Correct |
97 ms |
344 KB |
Output is correct |
8 |
Correct |
97 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
92 ms |
564 KB |
Output is correct |
4 |
Correct |
97 ms |
344 KB |
Output is correct |
5 |
Correct |
97 ms |
344 KB |
Output is correct |
6 |
Correct |
98 ms |
344 KB |
Output is correct |
7 |
Correct |
97 ms |
344 KB |
Output is correct |
8 |
Correct |
97 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
2472 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
2472 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
92 ms |
564 KB |
Output is correct |
4 |
Correct |
97 ms |
344 KB |
Output is correct |
5 |
Correct |
97 ms |
344 KB |
Output is correct |
6 |
Correct |
98 ms |
344 KB |
Output is correct |
7 |
Correct |
97 ms |
344 KB |
Output is correct |
8 |
Correct |
97 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
92 ms |
564 KB |
Output is correct |
4 |
Correct |
97 ms |
344 KB |
Output is correct |
5 |
Correct |
97 ms |
344 KB |
Output is correct |
6 |
Correct |
98 ms |
344 KB |
Output is correct |
7 |
Correct |
97 ms |
344 KB |
Output is correct |
8 |
Correct |
97 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |