답안 #1047236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047236 2024-08-07T11:11:11 Z alex_2008 Sprinklers (CEOI24_sprinklers) C++14
100 / 100
114 ms 3492 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int dp[N];
int from[N];
int s[N], f[N];
int n, m;
string ans_s = "";
int ind(int l, int r, int i) {
	while (i <= m && l <= f[i] && f[i] <= r) {
		i++;
	}
	i--;
	return i;
}
bool ch(int d) {
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		dp[i] = 0;
		int x = ind(s[i] - d, s[i], dp[i - 1] + 1);
		if (x >= dp[i]) {
			dp[i] = x;
			from[i] = 1;
		}
		x = ind(s[i], s[i] + d, dp[i - 1] + 1);
		if (x >= dp[i]) {
			dp[i] = x;
			from[i] = 2;
		}
		if (i != 1) {
			if (s[i - 1] + d >= s[i]) {
				x = ind(s[i] - d, s[i - 1] + d, dp[i - 2] + 1);
				if (x >= dp[i]) {
					dp[i] = x;
					from[i] = 3;
				}
			}
 		}
	}
	if (dp[n] < m) return false;
	ans_s.clear();
	int i = n;
	while (i != 0) {
		if (from[i] == 1) {
			ans_s.push_back('L');
			i--;
		}
		else if (from[i] == 2) {
			ans_s.push_back('R');
			i--;
		}
		else if (from[i] == 3) {
			ans_s.push_back('L');
			ans_s.push_back('R');
			i -= 2;
		}
	}
	return true;
}
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> f[i];
	}
	int l = 0, r = 1e9 + 10, ans = -1;
	while (l <= r) {
		int mid = (l + r) / 2;
		if (ch(mid)) {
			ans = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	cout << ans << "\n";
	if (ans == -1) return 0;
	reverse(ans_s.begin(), ans_s.end());
	cout << ans_s << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 18 ms 740 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 19 ms 816 KB Correct
5 Correct 19 ms 644 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 1 ms 348 KB Correct
8 Correct 4 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 26 ms 856 KB Correct
3 Correct 5 ms 600 KB Correct
4 Correct 61 ms 2196 KB Correct
5 Correct 65 ms 2128 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 53 ms 2128 KB Correct
9 Correct 51 ms 2384 KB Correct
10 Correct 55 ms 2232 KB Correct
11 Correct 32 ms 1876 KB Correct
12 Correct 35 ms 1104 KB Correct
13 Correct 44 ms 2128 KB Correct
14 Correct 49 ms 2132 KB Correct
15 Correct 57 ms 2128 KB Correct
16 Correct 42 ms 2068 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 0 ms 348 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 0 ms 344 KB Correct
12 Correct 1 ms 452 KB Correct
13 Correct 0 ms 348 KB Correct
14 Correct 0 ms 348 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 0 ms 348 KB Correct
18 Correct 1 ms 348 KB Correct
19 Correct 0 ms 452 KB Correct
20 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 27 ms 852 KB Correct
3 Correct 79 ms 2132 KB Correct
4 Correct 79 ms 3328 KB Correct
5 Correct 79 ms 3412 KB Correct
6 Correct 80 ms 3492 KB Correct
7 Correct 114 ms 3372 KB Correct
8 Correct 114 ms 3456 KB Correct
9 Correct 83 ms 3492 KB Correct
10 Correct 81 ms 3408 KB Correct
11 Correct 88 ms 3376 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 0 ms 440 KB Correct
14 Correct 40 ms 2584 KB Correct
15 Correct 39 ms 2644 KB Correct
16 Correct 39 ms 2532 KB Correct
17 Correct 36 ms 2624 KB Correct
18 Correct 45 ms 2572 KB Correct
19 Correct 44 ms 2984 KB Correct
20 Correct 75 ms 3248 KB Correct
21 Correct 66 ms 3176 KB Correct
22 Correct 59 ms 3152 KB Correct
23 Correct 60 ms 3268 KB Correct
24 Correct 55 ms 2904 KB Correct
25 Correct 55 ms 2968 KB Correct
26 Correct 33 ms 2384 KB Correct
27 Correct 27 ms 1628 KB Correct
28 Correct 50 ms 2836 KB Correct
29 Correct 46 ms 2716 KB Correct
30 Correct 49 ms 2900 KB Correct
31 Correct 47 ms 2896 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 18 ms 740 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 19 ms 816 KB Correct
6 Correct 19 ms 644 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 4 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 26 ms 856 KB Correct
12 Correct 5 ms 600 KB Correct
13 Correct 61 ms 2196 KB Correct
14 Correct 65 ms 2128 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 53 ms 2128 KB Correct
18 Correct 51 ms 2384 KB Correct
19 Correct 55 ms 2232 KB Correct
20 Correct 32 ms 1876 KB Correct
21 Correct 35 ms 1104 KB Correct
22 Correct 44 ms 2128 KB Correct
23 Correct 49 ms 2132 KB Correct
24 Correct 57 ms 2128 KB Correct
25 Correct 42 ms 2068 KB Correct
26 Correct 0 ms 348 KB Correct
27 Correct 0 ms 348 KB Correct
28 Correct 0 ms 348 KB Correct
29 Correct 0 ms 348 KB Correct
30 Correct 0 ms 348 KB Correct
31 Correct 0 ms 348 KB Correct
32 Correct 0 ms 348 KB Correct
33 Correct 0 ms 348 KB Correct
34 Correct 0 ms 344 KB Correct
35 Correct 1 ms 452 KB Correct
36 Correct 0 ms 348 KB Correct
37 Correct 0 ms 348 KB Correct
38 Correct 0 ms 348 KB Correct
39 Correct 0 ms 348 KB Correct
40 Correct 0 ms 348 KB Correct
41 Correct 1 ms 348 KB Correct
42 Correct 0 ms 452 KB Correct
43 Correct 0 ms 348 KB Correct
44 Correct 27 ms 852 KB Correct
45 Correct 79 ms 2132 KB Correct
46 Correct 79 ms 3328 KB Correct
47 Correct 79 ms 3412 KB Correct
48 Correct 80 ms 3492 KB Correct
49 Correct 114 ms 3372 KB Correct
50 Correct 114 ms 3456 KB Correct
51 Correct 83 ms 3492 KB Correct
52 Correct 81 ms 3408 KB Correct
53 Correct 88 ms 3376 KB Correct
54 Correct 0 ms 348 KB Correct
55 Correct 0 ms 440 KB Correct
56 Correct 40 ms 2584 KB Correct
57 Correct 39 ms 2644 KB Correct
58 Correct 39 ms 2532 KB Correct
59 Correct 36 ms 2624 KB Correct
60 Correct 45 ms 2572 KB Correct
61 Correct 44 ms 2984 KB Correct
62 Correct 75 ms 3248 KB Correct
63 Correct 66 ms 3176 KB Correct
64 Correct 59 ms 3152 KB Correct
65 Correct 60 ms 3268 KB Correct
66 Correct 55 ms 2904 KB Correct
67 Correct 55 ms 2968 KB Correct
68 Correct 33 ms 2384 KB Correct
69 Correct 27 ms 1628 KB Correct
70 Correct 50 ms 2836 KB Correct
71 Correct 46 ms 2716 KB Correct
72 Correct 49 ms 2900 KB Correct
73 Correct 47 ms 2896 KB Correct
74 Correct 24 ms 1616 KB Correct
75 Correct 79 ms 3408 KB Correct
76 Correct 82 ms 3412 KB Correct
77 Correct 0 ms 348 KB Correct
78 Correct 66 ms 3492 KB Correct
79 Correct 54 ms 3412 KB Correct
80 Correct 51 ms 3408 KB Correct
81 Correct 35 ms 2640 KB Correct
82 Correct 34 ms 2640 KB Correct
83 Correct 34 ms 2652 KB Correct
84 Correct 15 ms 1116 KB Correct
85 Correct 54 ms 3108 KB Correct
86 Correct 61 ms 3108 KB Correct
87 Correct 59 ms 2640 KB Correct
88 Correct 21 ms 1368 KB Correct
89 Correct 21 ms 1560 KB Correct