Submission #1043092

# Submission time Handle Problem Language Result Execution time Memory
1043092 2024-08-03T22:53:30 Z Tob Sprinklers (CEOI24_sprinklers) C++14
100 / 100
115 ms 7508 KB
#include <bits/stdc++.h>

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const int N = 1e5 + 7;

int n, m;
int a[N], b[N], dp[N], gt[N];
string t[N];

void update(int x, int y, int val, string s) {
	if (dp[y] < val) {
		dp[y] = val;
		gt[y] = x;
		t[y] = s;
	}
}
void check(int k) {	
	memset(dp, -1, sizeof dp);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		if (dp[i] == -1) continue;
		if (b[dp[i]]+k >= a[i] && b[dp[i]] <= a[i]) update(i, i+1, upper_bound(b, b+m, a[i])-b, "L");
		if (b[dp[i]] >= a[i] && a[i]+k >= b[dp[i]]) update(i, i+1, upper_bound(b, b+m, a[i]+k)-b, "R");
		if (a[i]+k < b[dp[i]]) update(i, i+1, dp[i], "R");
		if (i < n-1 && b[dp[i]] < a[i] && b[dp[i]]+k >= a[i+1]) update(i, i+2, upper_bound(b, b+m, a[i]+k)-b, "LR");
	}
}

int main () {
	FIO;
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < m; i++) cin >> b[i];
	b[m] = 2e9 + 7;
	
	if (n == 1 && a[0] > b[0] && a[n-1] < b[m-1]) {
		cout << "-1\n";
		return 0;
	}
	
	int lo = 0, hi = 1e9;
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		check(mid);
		if (dp[n] == m) hi = mid;
		else lo = mid+1;
	}
	cout << lo << "\n";
	check(lo);
	
	int x = n;
	string s;
	while (x) {
		s += t[x];
		x = gt[x];
	}
	reverse(all(s));
	cout << s;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Correct
2 Correct 1 ms 4700 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Correct
2 Correct 5 ms 4700 KB Correct
3 Correct 1 ms 4700 KB Correct
4 Correct 5 ms 4700 KB Correct
5 Correct 6 ms 4700 KB Correct
6 Correct 1 ms 4700 KB Correct
7 Correct 1 ms 4700 KB Correct
8 Correct 2 ms 4700 KB Correct
9 Correct 1 ms 4700 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Correct
2 Correct 8 ms 4700 KB Correct
3 Correct 5 ms 4700 KB Correct
4 Correct 49 ms 5384 KB Correct
5 Correct 53 ms 5200 KB Correct
6 Correct 1 ms 4696 KB Correct
7 Correct 1 ms 4700 KB Correct
8 Correct 24 ms 5412 KB Correct
9 Correct 23 ms 5464 KB Correct
10 Correct 30 ms 5204 KB Correct
11 Correct 30 ms 5212 KB Correct
12 Correct 25 ms 4956 KB Correct
13 Correct 43 ms 5204 KB Correct
14 Correct 55 ms 5204 KB Correct
15 Correct 52 ms 5204 KB Correct
16 Correct 39 ms 5200 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Correct
2 Correct 1 ms 4700 KB Correct
3 Correct 1 ms 4696 KB Correct
4 Correct 1 ms 4700 KB Correct
5 Correct 1 ms 4700 KB Correct
6 Correct 1 ms 4756 KB Correct
7 Correct 1 ms 4700 KB Correct
8 Correct 1 ms 4700 KB Correct
9 Correct 1 ms 4700 KB Correct
10 Correct 1 ms 4700 KB Correct
11 Correct 1 ms 4700 KB Correct
12 Correct 1 ms 4700 KB Correct
13 Correct 1 ms 4700 KB Correct
14 Correct 1 ms 4700 KB Correct
15 Correct 1 ms 4700 KB Correct
16 Correct 1 ms 4700 KB Correct
17 Correct 1 ms 4700 KB Correct
18 Correct 1 ms 4700 KB Correct
19 Correct 1 ms 4696 KB Correct
20 Correct 1 ms 4696 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Correct
2 Correct 27 ms 4700 KB Correct
3 Correct 89 ms 5204 KB Correct
4 Correct 107 ms 7508 KB Correct
5 Correct 97 ms 7320 KB Correct
6 Correct 95 ms 7252 KB Correct
7 Correct 108 ms 7252 KB Correct
8 Correct 97 ms 7320 KB Correct
9 Correct 95 ms 7248 KB Correct
10 Correct 104 ms 7248 KB Correct
11 Correct 115 ms 7248 KB Correct
12 Correct 1 ms 4700 KB Correct
13 Correct 1 ms 4700 KB Correct
14 Correct 26 ms 6236 KB Correct
15 Correct 26 ms 6224 KB Correct
16 Correct 26 ms 6224 KB Correct
17 Correct 26 ms 5968 KB Correct
18 Correct 43 ms 6156 KB Correct
19 Correct 33 ms 6228 KB Correct
20 Correct 77 ms 6996 KB Correct
21 Correct 93 ms 6992 KB Correct
22 Correct 68 ms 6736 KB Correct
23 Correct 67 ms 6736 KB Correct
24 Correct 56 ms 6556 KB Correct
25 Correct 56 ms 6480 KB Correct
26 Correct 39 ms 5972 KB Correct
27 Correct 36 ms 5468 KB Correct
28 Correct 55 ms 6732 KB Correct
29 Correct 50 ms 6368 KB Correct
30 Correct 53 ms 6392 KB Correct
31 Correct 67 ms 6300 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Correct
2 Correct 1 ms 4700 KB Correct
3 Correct 5 ms 4700 KB Correct
4 Correct 1 ms 4700 KB Correct
5 Correct 5 ms 4700 KB Correct
6 Correct 6 ms 4700 KB Correct
7 Correct 1 ms 4700 KB Correct
8 Correct 1 ms 4700 KB Correct
9 Correct 2 ms 4700 KB Correct
10 Correct 1 ms 4700 KB Correct
11 Correct 8 ms 4700 KB Correct
12 Correct 5 ms 4700 KB Correct
13 Correct 49 ms 5384 KB Correct
14 Correct 53 ms 5200 KB Correct
15 Correct 1 ms 4696 KB Correct
16 Correct 1 ms 4700 KB Correct
17 Correct 24 ms 5412 KB Correct
18 Correct 23 ms 5464 KB Correct
19 Correct 30 ms 5204 KB Correct
20 Correct 30 ms 5212 KB Correct
21 Correct 25 ms 4956 KB Correct
22 Correct 43 ms 5204 KB Correct
23 Correct 55 ms 5204 KB Correct
24 Correct 52 ms 5204 KB Correct
25 Correct 39 ms 5200 KB Correct
26 Correct 1 ms 4696 KB Correct
27 Correct 1 ms 4700 KB Correct
28 Correct 1 ms 4700 KB Correct
29 Correct 1 ms 4756 KB Correct
30 Correct 1 ms 4700 KB Correct
31 Correct 1 ms 4700 KB Correct
32 Correct 1 ms 4700 KB Correct
33 Correct 1 ms 4700 KB Correct
34 Correct 1 ms 4700 KB Correct
35 Correct 1 ms 4700 KB Correct
36 Correct 1 ms 4700 KB Correct
37 Correct 1 ms 4700 KB Correct
38 Correct 1 ms 4700 KB Correct
39 Correct 1 ms 4700 KB Correct
40 Correct 1 ms 4700 KB Correct
41 Correct 1 ms 4700 KB Correct
42 Correct 1 ms 4696 KB Correct
43 Correct 1 ms 4696 KB Correct
44 Correct 27 ms 4700 KB Correct
45 Correct 89 ms 5204 KB Correct
46 Correct 107 ms 7508 KB Correct
47 Correct 97 ms 7320 KB Correct
48 Correct 95 ms 7252 KB Correct
49 Correct 108 ms 7252 KB Correct
50 Correct 97 ms 7320 KB Correct
51 Correct 95 ms 7248 KB Correct
52 Correct 104 ms 7248 KB Correct
53 Correct 115 ms 7248 KB Correct
54 Correct 1 ms 4700 KB Correct
55 Correct 1 ms 4700 KB Correct
56 Correct 26 ms 6236 KB Correct
57 Correct 26 ms 6224 KB Correct
58 Correct 26 ms 6224 KB Correct
59 Correct 26 ms 5968 KB Correct
60 Correct 43 ms 6156 KB Correct
61 Correct 33 ms 6228 KB Correct
62 Correct 77 ms 6996 KB Correct
63 Correct 93 ms 6992 KB Correct
64 Correct 68 ms 6736 KB Correct
65 Correct 67 ms 6736 KB Correct
66 Correct 56 ms 6556 KB Correct
67 Correct 56 ms 6480 KB Correct
68 Correct 39 ms 5972 KB Correct
69 Correct 36 ms 5468 KB Correct
70 Correct 55 ms 6732 KB Correct
71 Correct 50 ms 6368 KB Correct
72 Correct 53 ms 6392 KB Correct
73 Correct 67 ms 6300 KB Correct
74 Correct 10 ms 5724 KB Correct
75 Correct 70 ms 7324 KB Correct
76 Correct 88 ms 7344 KB Correct
77 Correct 1 ms 4696 KB Correct
78 Correct 21 ms 7260 KB Correct
79 Correct 31 ms 7336 KB Correct
80 Correct 21 ms 7260 KB Correct
81 Correct 25 ms 6232 KB Correct
82 Correct 25 ms 6228 KB Correct
83 Correct 23 ms 6232 KB Correct
84 Correct 9 ms 5212 KB Correct
85 Correct 59 ms 6660 KB Correct
86 Correct 61 ms 6780 KB Correct
87 Correct 67 ms 6480 KB Correct
88 Correct 7 ms 5880 KB Correct
89 Correct 8 ms 5500 KB Correct