Submission #976278

# Submission time Handle Problem Language Result Execution time Memory
976278 2024-05-06T11:29:19 Z happypotato Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 11216 KB
#include "circuit.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
const ll MOD = 1e9 + 2022;
void chadd(ll &x, ll y) { x = (x + y) % MOD; }
void chmul(ll &x, ll y) { x = (x * y) % MOD; }
const int mxN = 2e5 + 10;
vector<int> adj[mxN];
int n, m;
bool state[mxN];
void init(int N, int M, vector<int> P, vector<int> A) {
	n = N; m = M;
	for (int i = 1; i < (int)(P.size()); i++) {
		adj[P[i]].pb(i);
	}
	for (int i = 0; i < (int)(A.size()); i++) {
		state[n + i] = A[i];
	}
}

ll dp[mxN][2];
ll poly[mxN];
void dfs(int u) {
	if (u >= n) {
		dp[u][0] = dp[u][1] = 0;
		dp[u][state[u]] = 1;
		return;
	}
	for (int v : adj[u]) dfs(v);
	int sz = adj[u].size();
	for (int i = 0; i <= sz; i++) poly[i] = (i == 0);
	for (int v : adj[u]) {
		// multiply by (c0 + c1*x)
		for (int i = sz; i >= 1; i--) {
			poly[i] = (poly[i] * dp[v][0] + poly[i - 1] * dp[v][1]) % MOD;
		}
		poly[0] = (poly[0] * dp[v][0]) % MOD;
	}
	dp[u][0] = dp[u][1] = 0;
	for (int i = 0; i <= sz; i++) {
		chadd(dp[u][0], (sz - i) * poly[i]);
		chadd(dp[u][1], i * poly[i]);
	}
};
int count_ways(int L, int R) {
	for (int i = L; i <= R; i++) state[i] ^= 1;
	dfs(0);
	return (int)(dp[0][1]);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 2 ms 7608 KB Output is correct
3 Correct 8 ms 7588 KB Output is correct
4 Correct 9 ms 7764 KB Output is correct
5 Correct 9 ms 7768 KB Output is correct
6 Correct 9 ms 7768 KB Output is correct
7 Correct 9 ms 7768 KB Output is correct
8 Correct 10 ms 7768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 2 ms 7768 KB Output is correct
3 Correct 3 ms 7768 KB Output is correct
4 Correct 2 ms 7768 KB Output is correct
5 Correct 2 ms 7768 KB Output is correct
6 Correct 2 ms 7768 KB Output is correct
7 Correct 2 ms 7768 KB Output is correct
8 Correct 2 ms 7768 KB Output is correct
9 Correct 2 ms 7768 KB Output is correct
10 Correct 2 ms 7768 KB Output is correct
11 Correct 2 ms 7768 KB Output is correct
12 Correct 2 ms 7844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 2 ms 7608 KB Output is correct
3 Correct 8 ms 7588 KB Output is correct
4 Correct 9 ms 7764 KB Output is correct
5 Correct 9 ms 7768 KB Output is correct
6 Correct 9 ms 7768 KB Output is correct
7 Correct 9 ms 7768 KB Output is correct
8 Correct 10 ms 7768 KB Output is correct
9 Correct 2 ms 7768 KB Output is correct
10 Correct 2 ms 7768 KB Output is correct
11 Correct 3 ms 7768 KB Output is correct
12 Correct 2 ms 7768 KB Output is correct
13 Correct 2 ms 7768 KB Output is correct
14 Correct 2 ms 7768 KB Output is correct
15 Correct 2 ms 7768 KB Output is correct
16 Correct 2 ms 7768 KB Output is correct
17 Correct 2 ms 7768 KB Output is correct
18 Correct 2 ms 7768 KB Output is correct
19 Correct 2 ms 7768 KB Output is correct
20 Correct 2 ms 7844 KB Output is correct
21 Correct 2 ms 7768 KB Output is correct
22 Correct 2 ms 7768 KB Output is correct
23 Correct 2 ms 7768 KB Output is correct
24 Correct 2 ms 7768 KB Output is correct
25 Correct 2 ms 7764 KB Output is correct
26 Correct 3 ms 7768 KB Output is correct
27 Correct 2 ms 7768 KB Output is correct
28 Correct 3 ms 7768 KB Output is correct
29 Correct 9 ms 7768 KB Output is correct
30 Correct 9 ms 7768 KB Output is correct
31 Correct 2 ms 7768 KB Output is correct
32 Correct 2 ms 7768 KB Output is correct
33 Correct 2 ms 7604 KB Output is correct
34 Correct 2 ms 7768 KB Output is correct
35 Correct 3 ms 7768 KB Output is correct
36 Correct 3 ms 7768 KB Output is correct
37 Correct 9 ms 7936 KB Output is correct
38 Correct 9 ms 7948 KB Output is correct
39 Correct 2 ms 7768 KB Output is correct
40 Correct 2 ms 7768 KB Output is correct
41 Correct 2 ms 7768 KB Output is correct
42 Correct 2 ms 7768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 11216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 11216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 2 ms 7768 KB Output is correct
3 Correct 3 ms 7768 KB Output is correct
4 Correct 2 ms 7768 KB Output is correct
5 Correct 2 ms 7768 KB Output is correct
6 Correct 2 ms 7768 KB Output is correct
7 Correct 2 ms 7768 KB Output is correct
8 Correct 2 ms 7768 KB Output is correct
9 Correct 2 ms 7768 KB Output is correct
10 Correct 2 ms 7768 KB Output is correct
11 Correct 2 ms 7768 KB Output is correct
12 Correct 2 ms 7844 KB Output is correct
13 Execution timed out 3069 ms 11216 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 2 ms 7608 KB Output is correct
3 Correct 8 ms 7588 KB Output is correct
4 Correct 9 ms 7764 KB Output is correct
5 Correct 9 ms 7768 KB Output is correct
6 Correct 9 ms 7768 KB Output is correct
7 Correct 9 ms 7768 KB Output is correct
8 Correct 10 ms 7768 KB Output is correct
9 Correct 2 ms 7768 KB Output is correct
10 Correct 2 ms 7768 KB Output is correct
11 Correct 3 ms 7768 KB Output is correct
12 Correct 2 ms 7768 KB Output is correct
13 Correct 2 ms 7768 KB Output is correct
14 Correct 2 ms 7768 KB Output is correct
15 Correct 2 ms 7768 KB Output is correct
16 Correct 2 ms 7768 KB Output is correct
17 Correct 2 ms 7768 KB Output is correct
18 Correct 2 ms 7768 KB Output is correct
19 Correct 2 ms 7768 KB Output is correct
20 Correct 2 ms 7844 KB Output is correct
21 Correct 2 ms 7768 KB Output is correct
22 Correct 2 ms 7768 KB Output is correct
23 Correct 2 ms 7768 KB Output is correct
24 Correct 2 ms 7768 KB Output is correct
25 Correct 2 ms 7764 KB Output is correct
26 Correct 3 ms 7768 KB Output is correct
27 Correct 2 ms 7768 KB Output is correct
28 Correct 3 ms 7768 KB Output is correct
29 Correct 9 ms 7768 KB Output is correct
30 Correct 9 ms 7768 KB Output is correct
31 Correct 2 ms 7768 KB Output is correct
32 Correct 2 ms 7768 KB Output is correct
33 Correct 2 ms 7604 KB Output is correct
34 Correct 2 ms 7768 KB Output is correct
35 Correct 3 ms 7768 KB Output is correct
36 Correct 3 ms 7768 KB Output is correct
37 Correct 9 ms 7936 KB Output is correct
38 Correct 9 ms 7948 KB Output is correct
39 Correct 2 ms 7768 KB Output is correct
40 Correct 2 ms 7768 KB Output is correct
41 Correct 2 ms 7768 KB Output is correct
42 Correct 2 ms 7768 KB Output is correct
43 Execution timed out 3037 ms 7768 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 2 ms 7608 KB Output is correct
3 Correct 8 ms 7588 KB Output is correct
4 Correct 9 ms 7764 KB Output is correct
5 Correct 9 ms 7768 KB Output is correct
6 Correct 9 ms 7768 KB Output is correct
7 Correct 9 ms 7768 KB Output is correct
8 Correct 10 ms 7768 KB Output is correct
9 Correct 2 ms 7768 KB Output is correct
10 Correct 2 ms 7768 KB Output is correct
11 Correct 3 ms 7768 KB Output is correct
12 Correct 2 ms 7768 KB Output is correct
13 Correct 2 ms 7768 KB Output is correct
14 Correct 2 ms 7768 KB Output is correct
15 Correct 2 ms 7768 KB Output is correct
16 Correct 2 ms 7768 KB Output is correct
17 Correct 2 ms 7768 KB Output is correct
18 Correct 2 ms 7768 KB Output is correct
19 Correct 2 ms 7768 KB Output is correct
20 Correct 2 ms 7844 KB Output is correct
21 Correct 2 ms 7768 KB Output is correct
22 Correct 2 ms 7768 KB Output is correct
23 Correct 2 ms 7768 KB Output is correct
24 Correct 2 ms 7768 KB Output is correct
25 Correct 2 ms 7764 KB Output is correct
26 Correct 3 ms 7768 KB Output is correct
27 Correct 2 ms 7768 KB Output is correct
28 Correct 3 ms 7768 KB Output is correct
29 Correct 9 ms 7768 KB Output is correct
30 Correct 9 ms 7768 KB Output is correct
31 Correct 2 ms 7768 KB Output is correct
32 Correct 2 ms 7768 KB Output is correct
33 Correct 2 ms 7604 KB Output is correct
34 Correct 2 ms 7768 KB Output is correct
35 Correct 3 ms 7768 KB Output is correct
36 Correct 3 ms 7768 KB Output is correct
37 Correct 9 ms 7936 KB Output is correct
38 Correct 9 ms 7948 KB Output is correct
39 Correct 2 ms 7768 KB Output is correct
40 Correct 2 ms 7768 KB Output is correct
41 Correct 2 ms 7768 KB Output is correct
42 Correct 2 ms 7768 KB Output is correct
43 Execution timed out 3069 ms 11216 KB Time limit exceeded
44 Halted 0 ms 0 KB -