#include <bits/stdc++.h>
#define int long long
using namespace std;
struct Obj {
int t, pos, i;
Obj(){}
Obj(int ti, int pi, int ii):t(ti),pos(pi),i(ii){}
};
bitset<20> bs;
bool trywith(vector<Obj>& a, int& n, int k) {
bool ok = false;
for(int i = 0; i < (1 << n) && !ok; i++) {
bitset<20> bit(i);
int l = -1, r = 0, last = 0;
for(int j = 0; j < a.size(); j++) {
if(!a[j].t) {
r = max(r, a[j].pos + 1);
if(l == a[j].pos) l = -1;
if(bit[a[j].i]) r = max(r, a[j].pos + k + 1);
else if(a[j].pos - k <= l) l = -1;
} else {
last = max(last, a[j].pos);
if(j >= r && l == -1) l = a[j].pos;
}
}
if(l == -1 && (r > last)) {
ok = true;
bs = bit;
}
}
return ok;
}
void solve() {
int n, m, temp;
cin >> n >> m;
vector<Obj> a;
for(int i = 0; i < n; i++) {
cin >> temp;
a.push_back(Obj(0, temp, i));
}
for(int i = 0; i < m; i++) {
cin >> temp;
a.push_back(Obj(1, temp, i));
}
sort(a.begin(), a.end(), [](Obj x, Obj y){
if(x.pos == y.pos) return x.t > y.t;
return x.pos < y.pos;
});
int l = 0, r = 1e9+1, mid, ans = -1;
while(l <= r) {
mid = (l + r) / 2;
if(trywith(a, n, mid)) {
r = mid - 1;
ans = mid;
} else l = mid + 1;
}
cout << ans << "\n";
if(ans != -1) {
for(int i = 0; i < n; i++) {
if(bs[i]) cout << 'R';
else cout << 'L';
}
cout << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Compilation message
Main.cpp: In function 'bool trywith(std::vector<Obj>&, long long int&, long long int)':
Main.cpp:17:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<Obj>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int j = 0; j < a.size(); j++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
12 ms |
3784 KB |
Correct |
3 |
Correct |
1 ms |
344 KB |
Correct |
4 |
Correct |
18 ms |
4364 KB |
Correct |
5 |
Correct |
27 ms |
4556 KB |
Correct |
6 |
Correct |
1 ms |
604 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
4 ms |
1368 KB |
Correct |
9 |
Correct |
1 ms |
600 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Incorrect |
277 ms |
3580 KB |
User solution is worse than jury's solution |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
3 |
Incorrect |
8 ms |
344 KB |
User solution is incorrect |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Execution timed out |
2058 ms |
3532 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
3 |
Correct |
12 ms |
3784 KB |
Correct |
4 |
Correct |
1 ms |
344 KB |
Correct |
5 |
Correct |
18 ms |
4364 KB |
Correct |
6 |
Correct |
27 ms |
4556 KB |
Correct |
7 |
Correct |
1 ms |
604 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
4 ms |
1368 KB |
Correct |
10 |
Correct |
1 ms |
600 KB |
Correct |
11 |
Incorrect |
277 ms |
3580 KB |
User solution is worse than jury's solution |
12 |
Halted |
0 ms |
0 KB |
- |