#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[i] <= f[k] && f[k] <= s[i] + d) {
used[k] = true;
}
}
}
else {
for (int k = 1; k <= m; k++) {
if (s[i] >= f[k] && f[k] >= s[i] - 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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Incorrect |
6 ms |
528 KB |
User solution is worse than jury's solution |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Incorrect |
52 ms |
344 KB |
User solution is incorrect |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Incorrect |
5 ms |
600 KB |
Unexpected end of file - int32 expected |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Incorrect |
6 ms |
528 KB |
User solution is worse than jury's solution |
4 |
Halted |
0 ms |
0 KB |
- |