Submission #1045919

# Submission time Handle Problem Language Result Execution time Memory
1045919 2024-08-06T08:32:18 Z alex_2008 Sprinklers (CEOI24_sprinklers) C++14
0 / 100
5 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;
}
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
	}
	for (int i = 1; i <= n; 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";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Incorrect 0 ms 348 KB User solution is incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB User solution is incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Incorrect 0 ms 348 KB User solution is incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Incorrect 5 ms 348 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Incorrect 0 ms 348 KB User solution is incorrect
3 Halted 0 ms 0 KB -