Submission #1014836

# Submission time Handle Problem Language Result Execution time Memory
1014836 2024-07-05T15:30:36 Z rainboy Fire (BOI24_fire) C
100 / 100
142 ms 62800 KB
#include <stdio.h>
#include <stdlib.h>

#define M	200000
#define N	(M * 2)

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

unsigned int Z = 12345;

int rand_() {
	return (Z *= 3) >> 1;
}

int xx[M * 2], ij[M * 2], m;

void sort(int *hh, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (xx[hh[j]] == xx[h])
				j++;
			else if (xx[hh[j]] < xx[h]) {
				tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
			}
		sort(hh, l, i);
		l = k;
	}
}

int *ej[N * 2], eo[N * 2], n;

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

int qu[N * 2], ans;

void dfs(int i, int d) {
	int o;

	qu[d] = i;
	if (i < n) {
		ans = min(ans, d + 1);
		while (ans > 0 && qu[d - (ans - 1)] - i >= n)
			ans--;
	}
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		dfs(j, d + 1);
	}
}

int main() {
	static int hh[M * 2], jj[N];
	int h, i, j;

	scanf("%d%*d", &m);
	for (h = 0; h < m * 2; h++)
		scanf("%d", &xx[h]);
	for (h = 0; h < m * 2; h++)
		hh[h] = h;
	sort(hh, 0, m * 2);
	n = 0;
	for (h = 0; h < m * 2; h++)
		ij[hh[h]] = h + 1 == m * 2 || xx[hh[h + 1]] != xx[hh[h]] ? n++ : n;
	for (i = 0; i < n; i++)
		jj[i] = i;
	for (h = 0; h < m; h++) {
		i = ij[h << 1 | 0], j = ij[h << 1 | 1];
		if (i < j)
			jj[i] = max(jj[i], j);
		else
			jj[0] = max(jj[0], j), jj[i] = max(jj[i], n + j);
	}
	for (i = 1; i < n; i++)
		jj[i] = max(jj[i], jj[i - 1]);
	for (i = 0; i < n; i++)
		if (jj[i] == i) {
			printf("-1\n");
			return 0;
		}
	for (i = 0; i < n * 2; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (i = 0; i < n; i++) {
		append(jj[i], i);
		if (jj[i] < n)
			append(n + jj[i], n + i);
	}
	ans = m;
	for (i = 0; i < n; i++)
		if (jj[i] >= n)
			dfs(n + i, 0);
	printf("%d\n", ans);
	return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:42:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   42 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:69:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  scanf("%d%*d", &m);
      |  ^~~~~~~~~~~~~~~~~~
Main.c:71:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   scanf("%d", &xx[h]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 388 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 372 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 388 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 372 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 3 ms 1628 KB Output is correct
40 Correct 3 ms 1884 KB Output is correct
41 Correct 3 ms 1372 KB Output is correct
42 Correct 2 ms 1536 KB Output is correct
43 Correct 2 ms 956 KB Output is correct
44 Correct 2 ms 1628 KB Output is correct
45 Correct 2 ms 1628 KB Output is correct
46 Correct 2 ms 1628 KB Output is correct
47 Correct 3 ms 1624 KB Output is correct
48 Correct 3 ms 1628 KB Output is correct
49 Correct 2 ms 1628 KB Output is correct
50 Correct 2 ms 1120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 0 ms 436 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Correct 3 ms 1376 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 1504 KB Output is correct
19 Correct 3 ms 1628 KB Output is correct
20 Correct 24 ms 5848 KB Output is correct
21 Correct 128 ms 49908 KB Output is correct
22 Correct 120 ms 49748 KB Output is correct
23 Correct 118 ms 46160 KB Output is correct
24 Correct 126 ms 55636 KB Output is correct
25 Correct 79 ms 22204 KB Output is correct
26 Correct 97 ms 34348 KB Output is correct
27 Correct 103 ms 47184 KB Output is correct
28 Correct 120 ms 49652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 3 ms 1352 KB Output is correct
14 Correct 2 ms 1116 KB Output is correct
15 Correct 25 ms 5844 KB Output is correct
16 Correct 99 ms 46360 KB Output is correct
17 Correct 140 ms 46164 KB Output is correct
18 Correct 142 ms 45904 KB Output is correct
19 Correct 121 ms 58328 KB Output is correct
20 Correct 91 ms 28876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 388 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 372 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 3 ms 1628 KB Output is correct
40 Correct 3 ms 1884 KB Output is correct
41 Correct 3 ms 1372 KB Output is correct
42 Correct 2 ms 1536 KB Output is correct
43 Correct 2 ms 956 KB Output is correct
44 Correct 2 ms 1628 KB Output is correct
45 Correct 2 ms 1628 KB Output is correct
46 Correct 2 ms 1628 KB Output is correct
47 Correct 3 ms 1624 KB Output is correct
48 Correct 3 ms 1628 KB Output is correct
49 Correct 2 ms 1628 KB Output is correct
50 Correct 2 ms 1120 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 352 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 352 KB Output is correct
61 Correct 0 ms 436 KB Output is correct
62 Correct 0 ms 352 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 352 KB Output is correct
65 Correct 3 ms 1376 KB Output is correct
66 Correct 2 ms 1372 KB Output is correct
67 Correct 2 ms 860 KB Output is correct
68 Correct 2 ms 1504 KB Output is correct
69 Correct 3 ms 1628 KB Output is correct
70 Correct 24 ms 5848 KB Output is correct
71 Correct 128 ms 49908 KB Output is correct
72 Correct 120 ms 49748 KB Output is correct
73 Correct 118 ms 46160 KB Output is correct
74 Correct 126 ms 55636 KB Output is correct
75 Correct 79 ms 22204 KB Output is correct
76 Correct 97 ms 34348 KB Output is correct
77 Correct 103 ms 47184 KB Output is correct
78 Correct 120 ms 49652 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 0 ms 348 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 0 ms 348 KB Output is correct
86 Correct 0 ms 348 KB Output is correct
87 Correct 0 ms 600 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 4 ms 1372 KB Output is correct
91 Correct 3 ms 1352 KB Output is correct
92 Correct 2 ms 1116 KB Output is correct
93 Correct 25 ms 5844 KB Output is correct
94 Correct 99 ms 46360 KB Output is correct
95 Correct 140 ms 46164 KB Output is correct
96 Correct 142 ms 45904 KB Output is correct
97 Correct 121 ms 58328 KB Output is correct
98 Correct 91 ms 28876 KB Output is correct
99 Correct 81 ms 10320 KB Output is correct
100 Correct 125 ms 49732 KB Output is correct
101 Correct 125 ms 62800 KB Output is correct
102 Correct 127 ms 59476 KB Output is correct
103 Correct 104 ms 47188 KB Output is correct
104 Correct 118 ms 49744 KB Output is correct
105 Correct 95 ms 53848 KB Output is correct