// Authors: Robert Jaworski
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
using namespace std;
bool check(int K, const std::vector<int>& s, const std::vector<int>& f, const vector<int>& c, bool verbose=false) {
vector<pair<int, int>> events; // place, type {-1: begin of cover interval, 0: flower, 1: end of cover interval} (order of types is important for sorting)
for(int it: f) events.push_back({it, 0});
for(int i=0; i<s.size(); i++)
{
if(c[i]==0)
{
events.push_back({s[i]-K, -1});
events.push_back({s[i], 1});
}
else
{
events.push_back({s[i], -1});
events.push_back({s[i]+K, 1});
}
}
sort(events.begin(), events.end());
int open_intervals=0;
for(auto [place, type]: events)
{
open_intervals -= type;
if(type == 0 && !open_intervals)
{
return false;
}
}
return true;
}
bool bruteforce(int N, int M, int K, const vector<int>& s, const vector<int>& f, std::vector<int>& conf) {
conf.resize(N, 0);
for (int i = 0; i != N;) {
if (check(K, s, f, conf)) return true;
for (i = 0; i < N; i++) {
conf[i] ^= 1;
if (conf[i]) break;
}
}
return false;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> s(N, 0), f(M, 0), conf;
for (auto&& x : s) {
cin >> x;
}
for (auto&& x : f) {
cin >> x;
}
if (N == 1) {
if (s.back() <= f[0]) {
cout << (f.back() - s.back()) << endl << "R" << endl;
}
else if (s[0] >= f.back()) {
cout << (s[0] - f[0]) << endl << "L" << endl;
}
else {
cout << -1 << endl;
}
return 0;
}
int maxK = 1;
int K, l, r;
if (bruteforce(N, M, 0, s, f, conf)) {
K = 0;
goto END;
}
while (!bruteforce(N, M, maxK, s, f, conf)) maxK <<= 1;
l = maxK / 2;
r = maxK;
while (l+1 < r) {
int m = (l+r) / 2;
if (bruteforce(N, M, m, s, f, conf)) {
r = m;
}
else {
l = m;
}
}
K = r;
if (!bruteforce(N, M, K, s, f, conf)) {
cout << "Very bad" << endl;
}
END:
cout << K << endl;
for (auto&& x : conf) {
cout << (x ? 'R' : 'L');
}
cout << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |