Submission #500564

# Submission time Handle Problem Language Result Execution time Memory
500564 2021-12-31T11:22:45 Z sidon Parachute rings (IOI12_rings) C++17
100 / 100
481 ms 48348 KB
#include <bits/stdc++.h>
using namespace std;

array<int, 2> g[1<<20];
int N, p, j;

struct Solver {
	int e[1<<20], d[1<<20] = {};
	int maxDeg = 0, cycle = -1, rem = -1;
	void add(int u, int v) {
		if(u == rem || v == rem || maxDeg > 2) return;
		maxDeg = max({maxDeg, ++d[u], ++d[v]});

		while(e[u] >= 0) u = e[u];
		while(e[v] >= 0) v = e[v];
		
		if(u == v) {
			cycle = cycle >= 0 ? N : u;
		} else {
			if(e[u] > e[v]) swap(u, v);
			e[u] += e[v], e[v] = u;
		}
	}
	int get() {
		if(maxDeg > 2) return 0;
		return cycle >= 0 ? e[cycle] : N;
	}
} s[5];

void Init(int N_) {
	N = N_;
	s[0].get();
	for(int i = 0; i < 5; i++)
		fill(s[i].e, s[i].e+N, -1);
}
void Link(int A, int B) {
	if(!p) {
		s[0].add(A, B);
		g[j++] = {A, B};
		if(s[0].maxDeg > 2) {
			for(int i = 0; i < N; i++)
				if(s[0].d[i] > 2) s[p=1].rem = i;
			for(int k = 0; k < j; k++)
				for(int i : {0, 1})
					if(g[k][i] == s[1].rem) s[++p].rem = g[k][!i];
			for(int i = 1; i < 5; i++)
				for(int k = 0; k < j; k++)
					s[i].add(g[k][0], g[k][1]);
		}
	} else
		for(int i = 1; i < 5; i++)
			s[i].add(A, B);
}
int CountCritical() {
	int res = 0;
	if(p)
		for(int i = 1; i < 5; i++)
			res += s[i].get() > 0;
	else res = abs(s[0].get());
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20740 KB Output is correct
2 Correct 8 ms 20940 KB Output is correct
3 Correct 9 ms 20940 KB Output is correct
4 Correct 7 ms 20812 KB Output is correct
5 Correct 9 ms 20940 KB Output is correct
6 Correct 9 ms 20916 KB Output is correct
7 Correct 9 ms 20940 KB Output is correct
8 Correct 9 ms 20940 KB Output is correct
9 Correct 13 ms 20968 KB Output is correct
10 Correct 10 ms 20940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 35132 KB Output is correct
2 Correct 266 ms 38620 KB Output is correct
3 Correct 179 ms 40492 KB Output is correct
4 Correct 322 ms 48136 KB Output is correct
5 Correct 299 ms 48192 KB Output is correct
6 Correct 318 ms 47944 KB Output is correct
7 Correct 176 ms 40504 KB Output is correct
8 Correct 435 ms 44268 KB Output is correct
9 Correct 481 ms 46908 KB Output is correct
10 Correct 262 ms 47684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20740 KB Output is correct
2 Correct 8 ms 20940 KB Output is correct
3 Correct 9 ms 20940 KB Output is correct
4 Correct 7 ms 20812 KB Output is correct
5 Correct 9 ms 20940 KB Output is correct
6 Correct 9 ms 20916 KB Output is correct
7 Correct 9 ms 20940 KB Output is correct
8 Correct 9 ms 20940 KB Output is correct
9 Correct 13 ms 20968 KB Output is correct
10 Correct 10 ms 20940 KB Output is correct
11 Correct 10 ms 20940 KB Output is correct
12 Correct 11 ms 21196 KB Output is correct
13 Correct 11 ms 21068 KB Output is correct
14 Correct 9 ms 21068 KB Output is correct
15 Correct 10 ms 21276 KB Output is correct
16 Correct 10 ms 21068 KB Output is correct
17 Correct 11 ms 21068 KB Output is correct
18 Correct 10 ms 21196 KB Output is correct
19 Correct 10 ms 21068 KB Output is correct
20 Correct 11 ms 21068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20740 KB Output is correct
2 Correct 8 ms 20940 KB Output is correct
3 Correct 9 ms 20940 KB Output is correct
4 Correct 7 ms 20812 KB Output is correct
5 Correct 9 ms 20940 KB Output is correct
6 Correct 9 ms 20916 KB Output is correct
7 Correct 9 ms 20940 KB Output is correct
8 Correct 9 ms 20940 KB Output is correct
9 Correct 13 ms 20968 KB Output is correct
10 Correct 10 ms 20940 KB Output is correct
11 Correct 10 ms 20940 KB Output is correct
12 Correct 11 ms 21196 KB Output is correct
13 Correct 11 ms 21068 KB Output is correct
14 Correct 9 ms 21068 KB Output is correct
15 Correct 10 ms 21276 KB Output is correct
16 Correct 10 ms 21068 KB Output is correct
17 Correct 11 ms 21068 KB Output is correct
18 Correct 10 ms 21196 KB Output is correct
19 Correct 10 ms 21068 KB Output is correct
20 Correct 11 ms 21068 KB Output is correct
21 Correct 19 ms 22220 KB Output is correct
22 Correct 25 ms 23116 KB Output is correct
23 Correct 29 ms 23668 KB Output is correct
24 Correct 34 ms 22772 KB Output is correct
25 Correct 20 ms 22936 KB Output is correct
26 Correct 29 ms 22828 KB Output is correct
27 Correct 28 ms 23324 KB Output is correct
28 Correct 27 ms 22604 KB Output is correct
29 Correct 28 ms 23072 KB Output is correct
30 Correct 28 ms 23620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20740 KB Output is correct
2 Correct 8 ms 20940 KB Output is correct
3 Correct 9 ms 20940 KB Output is correct
4 Correct 7 ms 20812 KB Output is correct
5 Correct 9 ms 20940 KB Output is correct
6 Correct 9 ms 20916 KB Output is correct
7 Correct 9 ms 20940 KB Output is correct
8 Correct 9 ms 20940 KB Output is correct
9 Correct 13 ms 20968 KB Output is correct
10 Correct 10 ms 20940 KB Output is correct
11 Correct 158 ms 35132 KB Output is correct
12 Correct 266 ms 38620 KB Output is correct
13 Correct 179 ms 40492 KB Output is correct
14 Correct 322 ms 48136 KB Output is correct
15 Correct 299 ms 48192 KB Output is correct
16 Correct 318 ms 47944 KB Output is correct
17 Correct 176 ms 40504 KB Output is correct
18 Correct 435 ms 44268 KB Output is correct
19 Correct 481 ms 46908 KB Output is correct
20 Correct 262 ms 47684 KB Output is correct
21 Correct 10 ms 20940 KB Output is correct
22 Correct 11 ms 21196 KB Output is correct
23 Correct 11 ms 21068 KB Output is correct
24 Correct 9 ms 21068 KB Output is correct
25 Correct 10 ms 21276 KB Output is correct
26 Correct 10 ms 21068 KB Output is correct
27 Correct 11 ms 21068 KB Output is correct
28 Correct 10 ms 21196 KB Output is correct
29 Correct 10 ms 21068 KB Output is correct
30 Correct 11 ms 21068 KB Output is correct
31 Correct 19 ms 22220 KB Output is correct
32 Correct 25 ms 23116 KB Output is correct
33 Correct 29 ms 23668 KB Output is correct
34 Correct 34 ms 22772 KB Output is correct
35 Correct 20 ms 22936 KB Output is correct
36 Correct 29 ms 22828 KB Output is correct
37 Correct 28 ms 23324 KB Output is correct
38 Correct 27 ms 22604 KB Output is correct
39 Correct 28 ms 23072 KB Output is correct
40 Correct 28 ms 23620 KB Output is correct
41 Correct 117 ms 34396 KB Output is correct
42 Correct 270 ms 42028 KB Output is correct
43 Correct 188 ms 40668 KB Output is correct
44 Correct 183 ms 39112 KB Output is correct
45 Correct 223 ms 41156 KB Output is correct
46 Correct 235 ms 44484 KB Output is correct
47 Correct 289 ms 44836 KB Output is correct
48 Correct 190 ms 42052 KB Output is correct
49 Correct 248 ms 48348 KB Output is correct
50 Correct 256 ms 47728 KB Output is correct
51 Correct 169 ms 37768 KB Output is correct
52 Correct 185 ms 35808 KB Output is correct
53 Correct 166 ms 41428 KB Output is correct
54 Correct 350 ms 40528 KB Output is correct
55 Correct 286 ms 38368 KB Output is correct