답안 #1047233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047233 2024-08-07T11:10:11 Z alex_2008 Sprinklers (CEOI24_sprinklers) C++14
9 / 100
66 ms 2208 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('R');
			ans_s.push_back('L');
			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 344 KB Correct
2 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 16 ms 724 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 19 ms 660 KB Correct
5 Correct 21 ms 604 KB Correct
6 Correct 1 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 4 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 20 ms 688 KB Correct
3 Correct 5 ms 604 KB Correct
4 Correct 53 ms 2052 KB Correct
5 Correct 64 ms 2132 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 48 ms 2172 KB Correct
9 Correct 46 ms 2128 KB Correct
10 Correct 50 ms 2208 KB Correct
11 Correct 29 ms 1884 KB Correct
12 Correct 37 ms 1324 KB Correct
13 Correct 38 ms 2132 KB Correct
14 Correct 42 ms 1952 KB Correct
15 Correct 60 ms 2072 KB Correct
16 Correct 36 ms 2128 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 0 ms 348 KB Correct
5 Incorrect 0 ms 348 KB User solution is worse than jury's solution
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 25 ms 860 KB Correct
3 Incorrect 66 ms 2080 KB User solution is worse than jury's solution
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 16 ms 724 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 19 ms 660 KB Correct
6 Correct 21 ms 604 KB Correct
7 Correct 1 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 4 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 20 ms 688 KB Correct
12 Correct 5 ms 604 KB Correct
13 Correct 53 ms 2052 KB Correct
14 Correct 64 ms 2132 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 48 ms 2172 KB Correct
18 Correct 46 ms 2128 KB Correct
19 Correct 50 ms 2208 KB Correct
20 Correct 29 ms 1884 KB Correct
21 Correct 37 ms 1324 KB Correct
22 Correct 38 ms 2132 KB Correct
23 Correct 42 ms 1952 KB Correct
24 Correct 60 ms 2072 KB Correct
25 Correct 36 ms 2128 KB Correct
26 Correct 0 ms 348 KB Correct
27 Correct 0 ms 348 KB Correct
28 Incorrect 0 ms 348 KB User solution is worse than jury's solution
29 Halted 0 ms 0 KB -