답안 #637191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637191 2022-08-31T22:12:27 Z blue 디지털 회로 (IOI22_circuit) C++17
50 / 100
3000 ms 14420 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define sz(x) int(x.size())

const ll mod = 1'000'002'022;

ll ad(ll a, ll b)
{
	return (a+b)%mod;
}

ll mul(ll a, ll b)
{
	return (a*b)%mod;
}

const int mx = 200'000;

vll Z(1 + mx, 0);
vll Zprod(1 + mx, 1);

vll coeff(1 + mx, 0);


vi children[1 + mx];
int N, M;

vi A;

ll res = 0;

void dfs(int u)
{
	for(int v : children[u])
	{
		Z[u]++;
		dfs(v);

		if(Z[v] != 0)
			Zprod[u] = mul(Zprod[u], Zprod[v]);
	}

	if(Z[u] != 0)
		Zprod[u] = mul(Zprod[u], Z[u]);

	// cerr << u << " : " << Z[u] << " | " << Zprod[u] << '\n';
}

void dfs2(int u, ll curr)
{
	coeff[u] = curr;
	// cerr << u << " -> " << curr << '\n';

	ll fwd[1 + sz(children[u]) + 1];
	ll bwd[1 + sz(children[u]) + 1];

	fwd[0] = 1;
	for(int e = 1; e <= sz(children[u]); e++)
		fwd[e] = mul(fwd[e-1], Zprod[ children[u][e - 1] ]);

	bwd[sz(children[u]) + 1] = 1;
	for(int e = sz(children[u]); e >= 1; e--)
		bwd[e] = mul(bwd[e+1], Zprod[ children[u][e - 1] ]);

	for(int e = 1; e <= sz(children[u]); e++)
	{
		// cerr << e << " : " << curr << ' ' << fwd[e-1] << ' ' << bwd[e+1] << '\n';
		dfs2(children[u][e - 1], mul(curr, mul(fwd[e-1], bwd[e+1])));
	}
}

void init(int N_, int M_, vi P_, vi A_)
{
	N = N_;
	M = M_;

	for(int i = 1; i < N+M; i++)
		children[P_[i]].push_back(i);

	dfs(0);
	dfs2(0, 1);

	A = vi(N, -1);
	for(int a : A_)
		A.push_back(a);

	// cerr << depth[1] << ' ' << depth[2] << '\n';

	for(int i = N; i < N+M; i++)
		res = ad(res, mul(A[i], coeff[i]));

	// cerr << "res = " << res << '\n';

	// for(int f : A)
	// 	cerr << f << '\n';
}

int count_ways(int L, int R)
{
	for(int i = L; i <= R; i++)
	{
		// res = ad(res, mul((!A[i]) - A[i], coeff[i]));
		if(A[i] == 0)
			res = ad(res, coeff[i]);
		else
			res = ad(res, mod - coeff[i]);
		A[i] = !A[i];
	}

	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 5 ms 9680 KB Output is correct
5 Correct 5 ms 9620 KB Output is correct
6 Correct 5 ms 9680 KB Output is correct
7 Correct 5 ms 9748 KB Output is correct
8 Correct 5 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 5 ms 9756 KB Output is correct
4 Correct 5 ms 9716 KB Output is correct
5 Correct 5 ms 9680 KB Output is correct
6 Correct 5 ms 9736 KB Output is correct
7 Correct 5 ms 9680 KB Output is correct
8 Correct 5 ms 9756 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 5 ms 9936 KB Output is correct
11 Correct 5 ms 9936 KB Output is correct
12 Correct 5 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 5 ms 9680 KB Output is correct
5 Correct 5 ms 9620 KB Output is correct
6 Correct 5 ms 9680 KB Output is correct
7 Correct 5 ms 9748 KB Output is correct
8 Correct 5 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 5 ms 9680 KB Output is correct
11 Correct 5 ms 9756 KB Output is correct
12 Correct 5 ms 9716 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9680 KB Output is correct
16 Correct 5 ms 9756 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9936 KB Output is correct
19 Correct 5 ms 9936 KB Output is correct
20 Correct 5 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 5 ms 9680 KB Output is correct
25 Correct 5 ms 9680 KB Output is correct
26 Correct 6 ms 9776 KB Output is correct
27 Correct 5 ms 9680 KB Output is correct
28 Correct 5 ms 9680 KB Output is correct
29 Correct 5 ms 9680 KB Output is correct
30 Correct 6 ms 9680 KB Output is correct
31 Correct 5 ms 9856 KB Output is correct
32 Correct 5 ms 9680 KB Output is correct
33 Correct 6 ms 9680 KB Output is correct
34 Correct 5 ms 9808 KB Output is correct
35 Correct 5 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 6 ms 9900 KB Output is correct
38 Correct 5 ms 10060 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9680 KB Output is correct
41 Correct 5 ms 9696 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 650 ms 11916 KB Output is correct
2 Correct 594 ms 14276 KB Output is correct
3 Correct 832 ms 14308 KB Output is correct
4 Correct 860 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 650 ms 11916 KB Output is correct
2 Correct 594 ms 14276 KB Output is correct
3 Correct 832 ms 14308 KB Output is correct
4 Correct 860 ms 14420 KB Output is correct
5 Execution timed out 3037 ms 12000 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 5 ms 9756 KB Output is correct
4 Correct 5 ms 9716 KB Output is correct
5 Correct 5 ms 9680 KB Output is correct
6 Correct 5 ms 9736 KB Output is correct
7 Correct 5 ms 9680 KB Output is correct
8 Correct 5 ms 9756 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 5 ms 9936 KB Output is correct
11 Correct 5 ms 9936 KB Output is correct
12 Correct 5 ms 9680 KB Output is correct
13 Correct 650 ms 11916 KB Output is correct
14 Correct 594 ms 14276 KB Output is correct
15 Correct 832 ms 14308 KB Output is correct
16 Correct 860 ms 14420 KB Output is correct
17 Execution timed out 3037 ms 12000 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 5 ms 9680 KB Output is correct
5 Correct 5 ms 9620 KB Output is correct
6 Correct 5 ms 9680 KB Output is correct
7 Correct 5 ms 9748 KB Output is correct
8 Correct 5 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 5 ms 9680 KB Output is correct
11 Correct 5 ms 9756 KB Output is correct
12 Correct 5 ms 9716 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9680 KB Output is correct
16 Correct 5 ms 9756 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9936 KB Output is correct
19 Correct 5 ms 9936 KB Output is correct
20 Correct 5 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 5 ms 9680 KB Output is correct
25 Correct 5 ms 9680 KB Output is correct
26 Correct 6 ms 9776 KB Output is correct
27 Correct 5 ms 9680 KB Output is correct
28 Correct 5 ms 9680 KB Output is correct
29 Correct 5 ms 9680 KB Output is correct
30 Correct 6 ms 9680 KB Output is correct
31 Correct 5 ms 9856 KB Output is correct
32 Correct 5 ms 9680 KB Output is correct
33 Correct 6 ms 9680 KB Output is correct
34 Correct 5 ms 9808 KB Output is correct
35 Correct 5 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 6 ms 9900 KB Output is correct
38 Correct 5 ms 10060 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9680 KB Output is correct
41 Correct 5 ms 9696 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
43 Correct 866 ms 9880 KB Output is correct
44 Correct 1049 ms 9936 KB Output is correct
45 Correct 1344 ms 9908 KB Output is correct
46 Correct 917 ms 10024 KB Output is correct
47 Correct 1698 ms 10024 KB Output is correct
48 Correct 1648 ms 10024 KB Output is correct
49 Correct 1366 ms 10056 KB Output is correct
50 Correct 2782 ms 10028 KB Output is correct
51 Correct 2822 ms 9936 KB Output is correct
52 Correct 1742 ms 9924 KB Output is correct
53 Correct 838 ms 10708 KB Output is correct
54 Correct 1508 ms 10068 KB Output is correct
55 Correct 1655 ms 9948 KB Output is correct
56 Correct 1468 ms 9916 KB Output is correct
57 Correct 1541 ms 9852 KB Output is correct
58 Correct 1626 ms 10800 KB Output is correct
59 Correct 1433 ms 10916 KB Output is correct
60 Correct 2632 ms 10912 KB Output is correct
61 Correct 1066 ms 10108 KB Output is correct
62 Correct 1332 ms 9876 KB Output is correct
63 Correct 1312 ms 9928 KB Output is correct
64 Correct 1651 ms 9876 KB Output is correct
65 Correct 590 ms 9840 KB Output is correct
66 Correct 1391 ms 9936 KB Output is correct
67 Correct 1381 ms 9996 KB Output is correct
68 Correct 2411 ms 9996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 5 ms 9680 KB Output is correct
5 Correct 5 ms 9620 KB Output is correct
6 Correct 5 ms 9680 KB Output is correct
7 Correct 5 ms 9748 KB Output is correct
8 Correct 5 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 5 ms 9680 KB Output is correct
11 Correct 5 ms 9756 KB Output is correct
12 Correct 5 ms 9716 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9736 KB Output is correct
15 Correct 5 ms 9680 KB Output is correct
16 Correct 5 ms 9756 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9936 KB Output is correct
19 Correct 5 ms 9936 KB Output is correct
20 Correct 5 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 5 ms 9680 KB Output is correct
25 Correct 5 ms 9680 KB Output is correct
26 Correct 6 ms 9776 KB Output is correct
27 Correct 5 ms 9680 KB Output is correct
28 Correct 5 ms 9680 KB Output is correct
29 Correct 5 ms 9680 KB Output is correct
30 Correct 6 ms 9680 KB Output is correct
31 Correct 5 ms 9856 KB Output is correct
32 Correct 5 ms 9680 KB Output is correct
33 Correct 6 ms 9680 KB Output is correct
34 Correct 5 ms 9808 KB Output is correct
35 Correct 5 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 6 ms 9900 KB Output is correct
38 Correct 5 ms 10060 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9680 KB Output is correct
41 Correct 5 ms 9696 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
43 Correct 650 ms 11916 KB Output is correct
44 Correct 594 ms 14276 KB Output is correct
45 Correct 832 ms 14308 KB Output is correct
46 Correct 860 ms 14420 KB Output is correct
47 Execution timed out 3037 ms 12000 KB Time limit exceeded
48 Halted 0 ms 0 KB -