#include "circuit.h"
#include <vector>
#include <iostream>
using namespace std;
const int MAXN = 100000;
const int MAXM = 100000;
int N, M;
//int P[MAXN+MAXM];
int A[MAXN+MAXM];
vector<int> adj[MAXN];
const int MOD = 1000002022;
int DP[MAXN + MAXM][2];
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
::N = N;
::M = M;
for (int i = 0; i < N+M; ++i) {
// ::P[i] = P[i];
int p = P[i];
adj[p].push_back(i);
}
for (int i = 0; i < M; ++i)
::A[i] = A[i];
for (int i = N; i < N+M; ++i)
DP[i][ A[i-N] ] = 1;
// cerr << "init finished" << endl;
}
int count_ways(int L, int R) {
// cerr << "L: " << L << " R:" << R << endl;
for (int i = L; i <= R; ++i) {
A[i-N] ^= 1;
if (A[i-N]) {
DP[i][0] = 0;
DP[i][1] = 1;
}
else {
DP[i][0] = 1;
DP[i][1] = 0;
}
}
/*
for (int i = 0; i < M; ++i)
cerr << A[i] << ' ';
cerr << endl;
*/
for (int u = N-1; u >= 0; --u) {
const int NC = adj[u].size();
vector<int> DPt(NC+1, 0);
DPt[0] = 1;
for (int j = 0; j < (int) adj[u].size(); ++j) {
int v = adj[u][j];
for (int ones = j+1; ones > 0; --ones) {
DPt[ones] = (DPt[ones ] * 1LL * DP[v][0] +
DPt[ones-1] * 1LL * DP[v][1]) % MOD;
}
DPt[0] = (DPt[0] * DP[v][0]) % MOD;
}
DP[u][0] = DP[u][1] = 0;
for (int ones = 0; ones <= NC; ++ones) {
DP[u][0] = (DP[u][0] + DPt[ones] * 1LL * (NC - ones)) % MOD;
DP[u][1] = (DP[u][1] + DPt[ones] * 1LL * ones) % MOD;
}
}
// for (int i = 0; i < N+M; ++i)
// cerr << i << ": " << DP[i][0] << ' ' << DP[i][1] << endl;
return DP[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
8 ms |
2640 KB |
Output is correct |
4 |
Correct |
8 ms |
2640 KB |
Output is correct |
5 |
Correct |
7 ms |
2692 KB |
Output is correct |
6 |
Correct |
6 ms |
2640 KB |
Output is correct |
7 |
Correct |
7 ms |
2640 KB |
Output is correct |
8 |
Correct |
7 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '27376734' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
8 ms |
2640 KB |
Output is correct |
4 |
Correct |
8 ms |
2640 KB |
Output is correct |
5 |
Correct |
7 ms |
2692 KB |
Output is correct |
6 |
Correct |
6 ms |
2640 KB |
Output is correct |
7 |
Correct |
7 ms |
2640 KB |
Output is correct |
8 |
Correct |
7 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '27376734' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3089 ms |
4816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3089 ms |
4816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '27376734' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
8 ms |
2640 KB |
Output is correct |
4 |
Correct |
8 ms |
2640 KB |
Output is correct |
5 |
Correct |
7 ms |
2692 KB |
Output is correct |
6 |
Correct |
6 ms |
2640 KB |
Output is correct |
7 |
Correct |
7 ms |
2640 KB |
Output is correct |
8 |
Correct |
7 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '27376734' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
8 ms |
2640 KB |
Output is correct |
4 |
Correct |
8 ms |
2640 KB |
Output is correct |
5 |
Correct |
7 ms |
2692 KB |
Output is correct |
6 |
Correct |
6 ms |
2640 KB |
Output is correct |
7 |
Correct |
7 ms |
2640 KB |
Output is correct |
8 |
Correct |
7 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '27376734' |
11 |
Halted |
0 ms |
0 KB |
- |