Submission #1060312

# Submission time Handle Problem Language Result Execution time Memory
1060312 2024-08-15T12:53:46 Z rainboy Sprinklers (CEOI24_sprinklers) C
100 / 100
77 ms 4052 KB
#include <stdio.h>
#include <string.h>
 
#define N	100000
#define M	100000
#define X	1000000001
 
int max(int a, int b) { return a > b ? a : b; }
 
char cc[N + 1]; int xx[N + 2], yy[M], n, m;
 
int solve(int d) {
	static int dp[N + 2], pp[N + 2];
	int i, i_, i1, j, x, y;
 
	memset(dp, -1, (n + 2) * sizeof *dp);
	dp[0] = 0;
	for (i = 0, i_ = 0, j = 0; i <= n; i++) {
		if (dp[i] == -1)
			continue;
		while (j < m && yy[j] < xx[i])
			j++;
		x = max(xx[i], xx[dp[i]] + d), y = -1;
		while (j < m && yy[j] < xx[i + 1]) {
			if (yy[j] > x) {
				y = yy[j];
				break;
			}
			j++;
		}
		if (y == -1)
			dp[i + 1] = i + 1, pp[i + 1] = i;
		else {
			i_ = max(i_, i + 1);
			while (i_ <= n + 1 && y >= xx[i_] - d) {
				i1 = i_ == i + 1 ? dp[i] : i_ - 1;
				if (dp[i_] < i1)
					dp[i_] = i1, pp[i_] = i;
				i_++;
			}
		}
	}
	if (dp[n + 1] == -1)
		return 0;
	memset(cc, 'R', n * sizeof *cc), cc[n] = 0;
	i = n;
	for (i = n; i > 0; i = pp[i])
		if (dp[i] != i)
			cc[i - 1] = 'L';
	return 1;
}
 
int main() {
	int m_, i, y, d, lower, upper;
 
	scanf("%d%d", &n, &m);
	xx[0] = -X - 1, xx[n + 1] = X * 2 + 1;
	for (i = 1; i <= n; i++)
		scanf("%d", &xx[i]);
	m_ = 0, i = 0;
	while (m--) {
		scanf("%d", &y);
		while (xx[i] < y)
			i++;
		if (xx[i] != y)
			yy[m_++] = y;
	}
	m = m_;
	lower = -1, upper = X;
	while (upper - lower > 1) {
		d = (lower + upper) / 2;
		if (solve(d))
			upper = d;
		else
			lower = d;
	}
	if (upper == X) {
		printf("-1\n");
		return 0;
	}
	solve(upper);
	printf("%d\n", upper);
	printf("%s\n", cc);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:56:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:59:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%d", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:62:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |   scanf("%d", &y);
      |   ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 7 ms 604 KB Correct
3 Correct 0 ms 344 KB Correct
4 Correct 17 ms 820 KB Correct
5 Correct 16 ms 600 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 2 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 10 ms 600 KB Correct
3 Correct 3 ms 344 KB Correct
4 Correct 56 ms 2060 KB Correct
5 Correct 38 ms 2132 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 40 ms 1880 KB Correct
9 Correct 31 ms 1696 KB Correct
10 Correct 41 ms 1896 KB Correct
11 Correct 22 ms 1700 KB Correct
12 Correct 19 ms 1264 KB Correct
13 Correct 34 ms 1880 KB Correct
14 Correct 35 ms 1880 KB Correct
15 Correct 35 ms 1884 KB Correct
16 Correct 32 ms 1872 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 1 ms 348 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 0 ms 348 KB Correct
6 Correct 0 ms 344 KB Correct
7 Correct 1 ms 348 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 1 ms 604 KB Correct
12 Correct 1 ms 344 KB Correct
13 Correct 1 ms 348 KB Correct
14 Correct 1 ms 348 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 344 KB Correct
17 Correct 0 ms 428 KB Correct
18 Correct 0 ms 344 KB Correct
19 Correct 0 ms 348 KB Correct
20 Correct 1 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 14 ms 876 KB Correct
3 Correct 57 ms 2028 KB Correct
4 Correct 54 ms 3968 KB Correct
5 Correct 53 ms 3928 KB Correct
6 Correct 54 ms 3932 KB Correct
7 Correct 60 ms 3944 KB Correct
8 Correct 69 ms 3944 KB Correct
9 Correct 69 ms 3880 KB Correct
10 Correct 60 ms 3848 KB Correct
11 Correct 77 ms 4052 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 0 ms 348 KB Correct
14 Correct 17 ms 2652 KB Correct
15 Correct 33 ms 2652 KB Correct
16 Correct 21 ms 2648 KB Correct
17 Correct 27 ms 2140 KB Correct
18 Correct 26 ms 2448 KB Correct
19 Correct 26 ms 2648 KB Correct
20 Correct 54 ms 3664 KB Correct
21 Correct 49 ms 3672 KB Correct
22 Correct 63 ms 3412 KB Correct
23 Correct 62 ms 3404 KB Correct
24 Correct 35 ms 2904 KB Correct
25 Correct 53 ms 3160 KB Correct
26 Correct 31 ms 2388 KB Correct
27 Correct 20 ms 1692 KB Correct
28 Correct 38 ms 2904 KB Correct
29 Correct 30 ms 2652 KB Correct
30 Correct 45 ms 3152 KB Correct
31 Correct 30 ms 2908 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 7 ms 604 KB Correct
4 Correct 0 ms 344 KB Correct
5 Correct 17 ms 820 KB Correct
6 Correct 16 ms 600 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 2 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 10 ms 600 KB Correct
12 Correct 3 ms 344 KB Correct
13 Correct 56 ms 2060 KB Correct
14 Correct 38 ms 2132 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 40 ms 1880 KB Correct
18 Correct 31 ms 1696 KB Correct
19 Correct 41 ms 1896 KB Correct
20 Correct 22 ms 1700 KB Correct
21 Correct 19 ms 1264 KB Correct
22 Correct 34 ms 1880 KB Correct
23 Correct 35 ms 1880 KB Correct
24 Correct 35 ms 1884 KB Correct
25 Correct 32 ms 1872 KB Correct
26 Correct 1 ms 348 KB Correct
27 Correct 0 ms 348 KB Correct
28 Correct 0 ms 348 KB Correct
29 Correct 0 ms 344 KB Correct
30 Correct 1 ms 348 KB Correct
31 Correct 1 ms 348 KB Correct
32 Correct 0 ms 348 KB Correct
33 Correct 0 ms 348 KB Correct
34 Correct 1 ms 604 KB Correct
35 Correct 1 ms 344 KB Correct
36 Correct 1 ms 348 KB Correct
37 Correct 1 ms 348 KB Correct
38 Correct 0 ms 348 KB Correct
39 Correct 0 ms 344 KB Correct
40 Correct 0 ms 428 KB Correct
41 Correct 0 ms 344 KB Correct
42 Correct 0 ms 348 KB Correct
43 Correct 1 ms 348 KB Correct
44 Correct 14 ms 876 KB Correct
45 Correct 57 ms 2028 KB Correct
46 Correct 54 ms 3968 KB Correct
47 Correct 53 ms 3928 KB Correct
48 Correct 54 ms 3932 KB Correct
49 Correct 60 ms 3944 KB Correct
50 Correct 69 ms 3944 KB Correct
51 Correct 69 ms 3880 KB Correct
52 Correct 60 ms 3848 KB Correct
53 Correct 77 ms 4052 KB Correct
54 Correct 0 ms 348 KB Correct
55 Correct 0 ms 348 KB Correct
56 Correct 17 ms 2652 KB Correct
57 Correct 33 ms 2652 KB Correct
58 Correct 21 ms 2648 KB Correct
59 Correct 27 ms 2140 KB Correct
60 Correct 26 ms 2448 KB Correct
61 Correct 26 ms 2648 KB Correct
62 Correct 54 ms 3664 KB Correct
63 Correct 49 ms 3672 KB Correct
64 Correct 63 ms 3412 KB Correct
65 Correct 62 ms 3404 KB Correct
66 Correct 35 ms 2904 KB Correct
67 Correct 53 ms 3160 KB Correct
68 Correct 31 ms 2388 KB Correct
69 Correct 20 ms 1692 KB Correct
70 Correct 38 ms 2904 KB Correct
71 Correct 30 ms 2652 KB Correct
72 Correct 45 ms 3152 KB Correct
73 Correct 30 ms 2908 KB Correct
74 Correct 11 ms 1624 KB Correct
75 Correct 52 ms 3928 KB Correct
76 Correct 49 ms 3932 KB Correct
77 Correct 0 ms 348 KB Correct
78 Correct 30 ms 3720 KB Correct
79 Correct 52 ms 3672 KB Correct
80 Correct 26 ms 3864 KB Correct
81 Correct 20 ms 2652 KB Correct
82 Correct 19 ms 2676 KB Correct
83 Correct 19 ms 2648 KB Correct
84 Correct 12 ms 1112 KB Correct
85 Correct 39 ms 3164 KB Correct
86 Correct 45 ms 3360 KB Correct
87 Correct 31 ms 2904 KB Correct
88 Correct 10 ms 1624 KB Correct
89 Correct 10 ms 1704 KB Correct