Submission #681567

# Submission time Handle Problem Language Result Execution time Memory
681567 2023-01-13T10:45:17 Z Justin1 Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 8272 KB
//0 - n-1 = non leaf, n - m-1 = leaf
 
#include "circuit.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
const int mod = 1e9 + 2022;
int n, m, k, x, y, z;
int val[200005], cont[200005], cur[200005];
vector<signed> par, gph[200005];

void dfs(int id) {
	val[id] = id >= n ? 1 : gph[id].size();
	for (auto i : gph[id]) dfs(i), val[id] = val[id] * val[i] % mod;
}

void dfs2(int id, int cur) {
	vector<int> pre(gph[id].size()+3, 1), post(gph[id].size()+3, 1);
	cont[id] = cur;
	for (int i = 1; i <= gph[id].size(); i++) pre[i] = pre[i-1] * val[gph[id][i-1]] % mod;
	for (int i = gph[id].size(); i >= 1; i--) post[i] = post[i+1] * val[gph[id][i-1]] % mod;
	for (int i = 1; i <= gph[id].size(); i++) dfs2(gph[id][i-1], cur * pre[i-1] % mod * post[i+1] % mod);
}
 
void init(signed N, signed M, std::vector<signed> P, std::vector<signed> A) {
	n = N, m = M, par = P;
	for (int i = 1; i < n + m; i++) gph[P[i]].push_back(i);
	for (int i = n; i < n + m; i++) cur[i] = A[i-n];
	dfs(0);
	dfs2(0, 1);
}

signed count_ways(signed L, signed R) {
	int ans = 0;
	for (int i = L; i <= R; i++) cur[i] ^= 1;
	for (int i = n; i < n + m; i++) {
		ans += cont[i] * cur[i];
		ans %= mod;
	}
	return ans;
}

Compilation message

circuit.cpp: In function 'void dfs2(long long int, long long int)':
circuit.cpp:21:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for (int i = 1; i <= gph[id].size(); i++) pre[i] = pre[i-1] * val[gph[id][i-1]] % mod;
      |                  ~~^~~~~~~~~~~~~~~~~
circuit.cpp:23:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i = 1; i <= gph[id].size(); i++) dfs2(gph[id][i-1], cur * pre[i-1] % mod * post[i+1] % mod);
      |                  ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 4988 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5040 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 4988 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5040 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 4 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 4972 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5352 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 8272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 8272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5040 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Execution timed out 3074 ms 8272 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 4988 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5040 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 4 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 4972 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5352 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 1358 ms 5200 KB Output is correct
44 Correct 1697 ms 5320 KB Output is correct
45 Correct 1951 ms 5284 KB Output is correct
46 Correct 2564 ms 5512 KB Output is correct
47 Correct 2808 ms 5456 KB Output is correct
48 Correct 2808 ms 5456 KB Output is correct
49 Correct 2837 ms 5516 KB Output is correct
50 Execution timed out 3050 ms 5456 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 4988 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5040 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 4 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 4972 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5352 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Execution timed out 3074 ms 8272 KB Time limit exceeded
44 Halted 0 ms 0 KB -