Submission #1018367

# Submission time Handle Problem Language Result Execution time Memory
1018367 2024-07-09T20:17:52 Z MohamedFaresNebili September (APIO24_september) C++17
100 / 100
115 ms 20812 KB
#include <bits/stdc++.h>

		using namespace std;

		vector<int> adj[100005];
		int par[100005];
		int lo[100005], hi[100005];

		int findSet(int v) {
			if(par[v] == v) return v;
			return par[v] = findSet(par[v]);
		}
		void unionSet(int u, int v) {
			u = findSet(u), v = findSet(v);
			if(u == v) return;
			par[u] = v;
			lo[v] = min(lo[v], lo[u]);
			hi[v] = max(hi[v], hi[u]);
		}

		void dfs(int v) {
			for(auto u : adj[v]) {
				dfs(u);
				hi[v] = max(hi[v], hi[u]);
			}
		}

		int solve(int N, int M, vector<int> F, vector<vector<int>> S) {
			for(int l = 0; l < N; l++) {
				adj[l].clear(), par[l] = l;
				lo[l] = N, hi[l] = 0;
			}

			for(int l = 1; l < N; l++) 
				adj[F[l]].push_back(l);
			
			for(int i = 0; i < M; i++)
				for(int l = 0; l < N - 1; l++) {
					lo[S[i][l]] = min(lo[S[i][l]], l);
					hi[S[i][l]] = max(hi[S[i][l]], l);
				}

			dfs(0);

			int res = 0;

			for(int i = 0; i < M; i++) {
				for(int l = 0; l < N - 1; l++) {
					if(lo[S[i][l]] < l)
						unionSet(S[i][l], S[i][l - 1]);
					if(hi[S[i][l]] > l)
						unionSet(S[i][l], S[i][l + 1]);
				}
			}
			for(int l = 1; l < N; l++)
				if(par[l] == l) ++res;
			

			return res;
		}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2820 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 1 ms 2820 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 3 ms 2908 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 2 ms 2828 KB Output is correct
33 Correct 2 ms 2908 KB Output is correct
34 Correct 2 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 102 ms 17288 KB Output is correct
5 Correct 99 ms 17020 KB Output is correct
6 Correct 106 ms 17152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2820 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 102 ms 17288 KB Output is correct
19 Correct 99 ms 17020 KB Output is correct
20 Correct 106 ms 17152 KB Output is correct
21 Correct 111 ms 12420 KB Output is correct
22 Correct 107 ms 12192 KB Output is correct
23 Correct 104 ms 13488 KB Output is correct
24 Correct 110 ms 13488 KB Output is correct
25 Correct 107 ms 12460 KB Output is correct
26 Correct 115 ms 12384 KB Output is correct
27 Correct 103 ms 13480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
7 Correct 102 ms 17288 KB Output is correct
8 Correct 99 ms 17020 KB Output is correct
9 Correct 106 ms 17152 KB Output is correct
10 Correct 64 ms 20680 KB Output is correct
11 Correct 79 ms 20812 KB Output is correct
12 Correct 65 ms 20684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 1 ms 2820 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 3 ms 2908 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 2 ms 2828 KB Output is correct
33 Correct 2 ms 2908 KB Output is correct
34 Correct 2 ms 2896 KB Output is correct
35 Correct 102 ms 17288 KB Output is correct
36 Correct 99 ms 17020 KB Output is correct
37 Correct 106 ms 17152 KB Output is correct
38 Correct 111 ms 12420 KB Output is correct
39 Correct 107 ms 12192 KB Output is correct
40 Correct 104 ms 13488 KB Output is correct
41 Correct 110 ms 13488 KB Output is correct
42 Correct 107 ms 12460 KB Output is correct
43 Correct 115 ms 12384 KB Output is correct
44 Correct 103 ms 13480 KB Output is correct
45 Correct 64 ms 20680 KB Output is correct
46 Correct 79 ms 20812 KB Output is correct
47 Correct 65 ms 20684 KB Output is correct
48 Correct 84 ms 14348 KB Output is correct
49 Correct 72 ms 14280 KB Output is correct
50 Correct 66 ms 15484 KB Output is correct
51 Correct 67 ms 15560 KB Output is correct
52 Correct 71 ms 14280 KB Output is correct
53 Correct 65 ms 14272 KB Output is correct
54 Correct 65 ms 15308 KB Output is correct