Submission #1045975

# Submission time Handle Problem Language Result Execution time Memory
1045975 2024-08-06T08:48:02 Z alex_2008 Sprinklers (CEOI24_sprinklers) C++14
0 / 100
0 ms 348 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";
	}
	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";
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Extra information in the output file
2 Halted 0 ms 0 KB -