답안 #1030015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030015 2024-07-21T16:08:45 Z 0npata 디지털 회로 (IOI22_circuit) C++17
22 / 100
3000 ms 13292 KB
#include "circuit.h"
#include<bits/stdc++.h>

using namespace std;

#define vec vector
#define int long long

const int MOD = 1'000'002'022;

const int MXN = 200'005;

int black[MXN];
int total[MXN];
int white[MXN];
vec<int32_t> par;

vec<int32_t> a;

vec<int> tree[MXN];
int n, m;

void compute(int u) {
	black[u] = 0;
	if(u >= n) {
		total[u] = 1;
		black[u] = a[u-n];
		white[u] = 1 - a[u-n];
		return;
	}
	 //cerr << "PROCESSING: " << u << '\n';
	total[u] = tree[u].size();
	for(int v : tree[u]) {
		total[u] *= total[v];
		total[u] %= MOD;
	}
	int k = tree[u].size();
	vec<vec<int>> h(k+1, vec<int>(k+1, 0));
	h[0][0] = 1;
	for(int i = 0; i<k; i++) {
		h[i+1][k] = h[i][k] * white[tree[u][i]];
		h[i+1][k] %= MOD;
		for(int j = 0; j<k; j++) {
			h[i+1][j] += h[i][j] * white[tree[u][i]];
			h[i+1][j] %= MOD;
			h[i+1][j+1] += h[i][j] * black[tree[u][i]];
			h[i+1][j+1] %= MOD;
		}
	}


	for(int i = 0; i<=k; i++) {
		black[u] += h[k][i]*i;
		black[u] %= MOD;
	}
	white[u] = total[u] + MOD - black[u];
	white[u] %= MOD;

//	 cerr << "BLACK: " << black[u] << " WHITE: " << white[u] << '\n';
}

void dfs1(int u = 0) {
	for(int v : tree[u]) {
		dfs1(v);
	}
	compute(u);
}

void init(int32_t N, int32_t M, std::vector<int32_t> P, std::vector<int32_t> A) {
	n = N;
	m = M;
	a = A;
	par = P;

	for(int i = 1; i<N+M; i++) {
		tree[P[i]].push_back(i);
	}
	dfs1();
}

int32_t count_ways(int32_t L, int32_t R) {

	if( L == R) {
		a[L-n] = 1-a[L-n];
		int cur = L;
		while(cur != -1) {
			compute(cur);
			cur = par[cur];
		}
	}
	else {
		for(int i = L; i<=R; i++) {
			a[i-n] = 1-a[i-n];
		}
		dfs1();
	}

	return black[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 36 ms 12632 KB Output is correct
4 Correct 56 ms 13092 KB Output is correct
5 Correct 41 ms 13124 KB Output is correct
6 Correct 36 ms 13092 KB Output is correct
7 Correct 48 ms 13292 KB Output is correct
8 Correct 41 ms 13108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4960 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 5 ms 4952 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 4 ms 5208 KB Output is correct
8 Correct 4 ms 5208 KB Output is correct
9 Correct 4 ms 5208 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 7 ms 5208 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 36 ms 12632 KB Output is correct
4 Correct 56 ms 13092 KB Output is correct
5 Correct 41 ms 13124 KB Output is correct
6 Correct 36 ms 13092 KB Output is correct
7 Correct 48 ms 13292 KB Output is correct
8 Correct 41 ms 13108 KB Output is correct
9 Correct 4 ms 4960 KB Output is correct
10 Correct 4 ms 4952 KB Output is correct
11 Correct 3 ms 5208 KB Output is correct
12 Correct 5 ms 4952 KB Output is correct
13 Correct 4 ms 4952 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 4 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 7 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 5 ms 5208 KB Output is correct
23 Correct 4 ms 5208 KB Output is correct
24 Correct 4 ms 5208 KB Output is correct
25 Correct 5 ms 5208 KB Output is correct
26 Correct 4 ms 5208 KB Output is correct
27 Correct 4 ms 5208 KB Output is correct
28 Correct 5 ms 5208 KB Output is correct
29 Correct 42 ms 13108 KB Output is correct
30 Correct 48 ms 13124 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 10 ms 5608 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 40 ms 13188 KB Output is correct
38 Correct 39 ms 13180 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 4 ms 5208 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 667 ms 8792 KB Output is correct
2 Correct 1057 ms 12556 KB Output is correct
3 Correct 1094 ms 12560 KB Output is correct
4 Correct 1127 ms 12436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 667 ms 8792 KB Output is correct
2 Correct 1057 ms 12556 KB Output is correct
3 Correct 1094 ms 12560 KB Output is correct
4 Correct 1127 ms 12436 KB Output is correct
5 Execution timed out 3059 ms 8788 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4960 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 5 ms 4952 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 4 ms 5208 KB Output is correct
8 Correct 4 ms 5208 KB Output is correct
9 Correct 4 ms 5208 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 7 ms 5208 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
13 Correct 667 ms 8792 KB Output is correct
14 Correct 1057 ms 12556 KB Output is correct
15 Correct 1094 ms 12560 KB Output is correct
16 Correct 1127 ms 12436 KB Output is correct
17 Execution timed out 3059 ms 8788 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 36 ms 12632 KB Output is correct
4 Correct 56 ms 13092 KB Output is correct
5 Correct 41 ms 13124 KB Output is correct
6 Correct 36 ms 13092 KB Output is correct
7 Correct 48 ms 13292 KB Output is correct
8 Correct 41 ms 13108 KB Output is correct
9 Correct 4 ms 4960 KB Output is correct
10 Correct 4 ms 4952 KB Output is correct
11 Correct 3 ms 5208 KB Output is correct
12 Correct 5 ms 4952 KB Output is correct
13 Correct 4 ms 4952 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 4 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 7 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 5 ms 5208 KB Output is correct
23 Correct 4 ms 5208 KB Output is correct
24 Correct 4 ms 5208 KB Output is correct
25 Correct 5 ms 5208 KB Output is correct
26 Correct 4 ms 5208 KB Output is correct
27 Correct 4 ms 5208 KB Output is correct
28 Correct 5 ms 5208 KB Output is correct
29 Correct 42 ms 13108 KB Output is correct
30 Correct 48 ms 13124 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 10 ms 5608 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 40 ms 13188 KB Output is correct
38 Correct 39 ms 13180 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 4 ms 5208 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5148 KB Output is correct
43 Execution timed out 3062 ms 5288 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 4 ms 4952 KB Output is correct
3 Correct 36 ms 12632 KB Output is correct
4 Correct 56 ms 13092 KB Output is correct
5 Correct 41 ms 13124 KB Output is correct
6 Correct 36 ms 13092 KB Output is correct
7 Correct 48 ms 13292 KB Output is correct
8 Correct 41 ms 13108 KB Output is correct
9 Correct 4 ms 4960 KB Output is correct
10 Correct 4 ms 4952 KB Output is correct
11 Correct 3 ms 5208 KB Output is correct
12 Correct 5 ms 4952 KB Output is correct
13 Correct 4 ms 4952 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 4 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 7 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 5 ms 5208 KB Output is correct
23 Correct 4 ms 5208 KB Output is correct
24 Correct 4 ms 5208 KB Output is correct
25 Correct 5 ms 5208 KB Output is correct
26 Correct 4 ms 5208 KB Output is correct
27 Correct 4 ms 5208 KB Output is correct
28 Correct 5 ms 5208 KB Output is correct
29 Correct 42 ms 13108 KB Output is correct
30 Correct 48 ms 13124 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 10 ms 5608 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 40 ms 13188 KB Output is correct
38 Correct 39 ms 13180 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 4 ms 5208 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5148 KB Output is correct
43 Correct 667 ms 8792 KB Output is correct
44 Correct 1057 ms 12556 KB Output is correct
45 Correct 1094 ms 12560 KB Output is correct
46 Correct 1127 ms 12436 KB Output is correct
47 Execution timed out 3059 ms 8788 KB Time limit exceeded
48 Halted 0 ms 0 KB -