Submission #393066

# Submission time Handle Problem Language Result Execution time Memory
393066 2021-04-22T16:04:41 Z rainboy Parachute rings (IOI12_rings) C
100 / 100
1048 ms 63288 KB
#include <string.h>

#define N	1000000
#define M	1000000

int find(int *ds, int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds, ds[i]));
}

int join(int *ds, int i, int j) {
	i = find(ds, i);
	j = find(ds, j);
	if (i == j)
		return 0;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
	return 1;
}

char critical[4]; int uu[4], ds[4][N], dd[4][N], adj[N][3], ii[M], jj[M], n, m, cnt, mode;

void Init(int n_) {
	n = n_, cnt = n, mode = 0;
	memset(ds[0], -1, n * sizeof *ds[0]);
}

void mode1(int i) {
	int j;

	mode = 1, cnt = 0;
	for (j = 0; j < n; j++)
		if (find(ds[0], j) == find(ds[0], i))
			cnt++;
}

void mode2(int i) {
	int h;

	mode = 2;
	for (h = 0; h < 4; h++) {
		uu[h] = h < 3 ? adj[i][h] : i, critical[h] = 1;
		memset(ds[h], -1, n * sizeof *ds[h]);
		memset(dd[h], 0, n * sizeof *dd[h]);
	}
	while (m--) {
		int i = ii[m], j = jj[m];

		for (h = 0; h < 4; h++) {
			int u = uu[h];

			if (i == u || j == u)
				continue;
			if (++dd[h][i] > 2)
				critical[h] = 0;
			if (++dd[h][j] > 2)
				critical[h] = 0;
			if (!join(ds[h], i, j))
				critical[h] = 0;
		}
	}
}

void mode3() {
	mode = 3, cnt = 0;
}

void Link(int i, int j) {
	if (mode <= 1) {
		ii[m] = i, jj[m] = j, m++;
		adj[i][dd[0][i]++] = j, adj[j][dd[0][j]++] = i;
		if (dd[0][i] > 2)
			mode2(i);
		else if (dd[0][j] > 2)
			mode2(j);
		else if (!join(ds[0], i, j)) {
			if (mode == 0)
				mode1(i);
			else
				mode3();
		}
	} else if (mode == 2) {
		int h;

		for (h = 0; h < 4; h++) {
			int u = uu[h];

			if (i == u || j == u)
				continue;
			if (++dd[h][i] > 2)
				critical[h] = 0;
			if (++dd[h][j] > 2)
				critical[h] = 0;
			if (!join(ds[h], i, j))
				critical[h] = 0;
		}
	}
}

int CountCritical() {
	if (mode == 2) {
		int h;

		cnt = 0;
		for (h = 0; h < 4; h++)
			if (critical[h])
				cnt++;
	}
	return cnt;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 14512 KB Output is correct
2 Correct 741 ms 36912 KB Output is correct
3 Correct 867 ms 43296 KB Output is correct
4 Correct 562 ms 27716 KB Output is correct
5 Correct 621 ms 41200 KB Output is correct
6 Correct 574 ms 40368 KB Output is correct
7 Correct 788 ms 55472 KB Output is correct
8 Correct 975 ms 58200 KB Output is correct
9 Correct 1048 ms 63288 KB Output is correct
10 Correct 467 ms 39904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 4 ms 844 KB Output is correct
13 Correct 4 ms 972 KB Output is correct
14 Correct 3 ms 844 KB Output is correct
15 Correct 3 ms 1228 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 4 ms 1356 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 6 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 4 ms 844 KB Output is correct
13 Correct 4 ms 972 KB Output is correct
14 Correct 3 ms 844 KB Output is correct
15 Correct 3 ms 1228 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 4 ms 1356 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 6 ms 972 KB Output is correct
21 Correct 14 ms 2124 KB Output is correct
22 Correct 23 ms 3076 KB Output is correct
23 Correct 29 ms 3744 KB Output is correct
24 Correct 34 ms 4292 KB Output is correct
25 Correct 15 ms 3968 KB Output is correct
26 Correct 36 ms 5388 KB Output is correct
27 Correct 34 ms 3624 KB Output is correct
28 Correct 43 ms 5284 KB Output is correct
29 Correct 33 ms 5416 KB Output is correct
30 Correct 46 ms 4168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 237 ms 14512 KB Output is correct
12 Correct 741 ms 36912 KB Output is correct
13 Correct 867 ms 43296 KB Output is correct
14 Correct 562 ms 27716 KB Output is correct
15 Correct 621 ms 41200 KB Output is correct
16 Correct 574 ms 40368 KB Output is correct
17 Correct 788 ms 55472 KB Output is correct
18 Correct 975 ms 58200 KB Output is correct
19 Correct 1048 ms 63288 KB Output is correct
20 Correct 467 ms 39904 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 4 ms 844 KB Output is correct
23 Correct 4 ms 972 KB Output is correct
24 Correct 3 ms 844 KB Output is correct
25 Correct 3 ms 1228 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 4 ms 844 KB Output is correct
28 Correct 4 ms 1356 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 6 ms 972 KB Output is correct
31 Correct 14 ms 2124 KB Output is correct
32 Correct 23 ms 3076 KB Output is correct
33 Correct 29 ms 3744 KB Output is correct
34 Correct 34 ms 4292 KB Output is correct
35 Correct 15 ms 3968 KB Output is correct
36 Correct 36 ms 5388 KB Output is correct
37 Correct 34 ms 3624 KB Output is correct
38 Correct 43 ms 5284 KB Output is correct
39 Correct 33 ms 5416 KB Output is correct
40 Correct 46 ms 4168 KB Output is correct
41 Correct 169 ms 17480 KB Output is correct
42 Correct 484 ms 48172 KB Output is correct
43 Correct 259 ms 34816 KB Output is correct
44 Correct 569 ms 49876 KB Output is correct
45 Correct 590 ms 52804 KB Output is correct
46 Correct 472 ms 35276 KB Output is correct
47 Correct 525 ms 35892 KB Output is correct
48 Correct 417 ms 51396 KB Output is correct
49 Correct 467 ms 38132 KB Output is correct
50 Correct 435 ms 37604 KB Output is correct
51 Correct 277 ms 34404 KB Output is correct
52 Correct 495 ms 41808 KB Output is correct
53 Correct 394 ms 49372 KB Output is correct
54 Correct 828 ms 50168 KB Output is correct
55 Correct 860 ms 50256 KB Output is correct