답안 #1045980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045980 2024-08-06T08:48:58 Z alex_2008 Sprinklers (CEOI24_sprinklers) C++14
26 / 100
178 ms 3420 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
bool used[N];
int s[N], f[N];
int n, m;
string ans_s = "";
bool ch(int d) {
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 1; j <= m; j++) {
			used[j] = false;
		}
		for (int j = 1; j <= n; j++) {
			if (i & (1 << (j - 1))) {
				for (int k = 1; k <= m; k++) {
					if (s[j] <= f[k] && f[k] <= s[j] + d) {
						used[k] = true;
					}
				}
			}
			else {
				for (int k = 1; k <= m; k++) {
					if (s[j] >= f[k] && f[k] >= s[j] - d) {
						used[k] = true;
					}
				}
			}
		}
		bool ch = true;
		for (int j = 1; j <= m; j++) {
			ch = min(ch, used[j]);
		}
		if (ch) {
			ans_s.clear();
			for (int j = 1; j <= n; j++) {
				if (i & (1 << (j - 1))) {
					ans_s.push_back('R');
				}
				else {
					ans_s.push_back('L');
				}
			}
			return true;
		}
	}
	return false;
}
bool ch2(int d) {
	vector <pair<int, int>> v;
	for (int i = 1; i <= n; i++) {
		if (v.empty()) {
			v.push_back({ s[i] - d, s[i] + d });
		}
		else {
			pair <int, int> cur = { s[i] - d, s[i] + d };
			if (v.back().second < cur.first) v.push_back(cur);
			else v.back().second = cur.second;
		}
	}
	for (int i = 1; i <= m; i++) {
		pair <int, int> x = make_pair(f[i], 2000000030);
		auto it = upper_bound(v.begin(), v.end(), x);
		if (it == v.begin()) return false;
		it--;
		if (it->second < f[i]) return false;
	}
	ans_s.clear();
	for (int i = 1; i <= n; i++) {
		if (s[i] != s[i - 1]) ans_s.push_back('L');
		else {
			if (ans_s[i - 2] == 'L') ans_s.push_back('R');
			else ans_s.push_back('L');
		}
	}
	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];
	}
	if ((n <= 10 && m <= 1000) || n == 1) {
		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) cout << ans_s << "\n";
		return 0;
	}
	int l = 0, r = 1e9 + 10, ans = -1;
	while (l <= r) {
		int mid = (l + r) / 2;
		if (ch2(mid)) {
			ans = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	cout << ans << "\n";
	if (ans != -1) cout << ans_s << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 21 ms 1484 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 30 ms 1756 KB Correct
5 Correct 27 ms 1880 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 1 ms 344 KB Correct
8 Correct 5 ms 604 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 40 ms 1076 KB Correct
3 Correct 6 ms 600 KB Correct
4 Correct 88 ms 3412 KB Correct
5 Correct 56 ms 3408 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 1 ms 600 KB Correct
8 Correct 59 ms 3364 KB Correct
9 Correct 54 ms 3420 KB Correct
10 Correct 102 ms 3264 KB Correct
11 Correct 38 ms 1872 KB Correct
12 Correct 52 ms 2248 KB Correct
13 Correct 47 ms 2500 KB Correct
14 Correct 46 ms 2728 KB Correct
15 Correct 81 ms 2852 KB Correct
16 Correct 56 ms 2592 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 79 ms 348 KB Correct
4 Correct 7 ms 352 KB Correct
5 Correct 165 ms 352 KB Correct
6 Correct 178 ms 436 KB Correct
7 Correct 2 ms 352 KB Correct
8 Correct 146 ms 356 KB Correct
9 Correct 105 ms 348 KB Correct
10 Correct 120 ms 456 KB Correct
11 Correct 21 ms 352 KB Correct
12 Correct 170 ms 760 KB Correct
13 Correct 131 ms 356 KB Correct
14 Correct 11 ms 360 KB Correct
15 Correct 26 ms 360 KB Correct
16 Correct 32 ms 356 KB Correct
17 Correct 44 ms 352 KB Correct
18 Correct 17 ms 464 KB Correct
19 Correct 1 ms 352 KB Correct
20 Correct 1 ms 360 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Incorrect 51 ms 1540 KB User solution is incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 21 ms 1484 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 30 ms 1756 KB Correct
6 Correct 27 ms 1880 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 344 KB Correct
9 Correct 5 ms 604 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 40 ms 1076 KB Correct
12 Correct 6 ms 600 KB Correct
13 Correct 88 ms 3412 KB Correct
14 Correct 56 ms 3408 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 1 ms 600 KB Correct
17 Correct 59 ms 3364 KB Correct
18 Correct 54 ms 3420 KB Correct
19 Correct 102 ms 3264 KB Correct
20 Correct 38 ms 1872 KB Correct
21 Correct 52 ms 2248 KB Correct
22 Correct 47 ms 2500 KB Correct
23 Correct 46 ms 2728 KB Correct
24 Correct 81 ms 2852 KB Correct
25 Correct 56 ms 2592 KB Correct
26 Correct 79 ms 348 KB Correct
27 Correct 7 ms 352 KB Correct
28 Correct 165 ms 352 KB Correct
29 Correct 178 ms 436 KB Correct
30 Correct 2 ms 352 KB Correct
31 Correct 146 ms 356 KB Correct
32 Correct 105 ms 348 KB Correct
33 Correct 120 ms 456 KB Correct
34 Correct 21 ms 352 KB Correct
35 Correct 170 ms 760 KB Correct
36 Correct 131 ms 356 KB Correct
37 Correct 11 ms 360 KB Correct
38 Correct 26 ms 360 KB Correct
39 Correct 32 ms 356 KB Correct
40 Correct 44 ms 352 KB Correct
41 Correct 17 ms 464 KB Correct
42 Correct 1 ms 352 KB Correct
43 Correct 1 ms 360 KB Correct
44 Incorrect 51 ms 1540 KB User solution is incorrect
45 Halted 0 ms 0 KB -