#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 <= 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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
20 ms |
856 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
26 ms |
756 KB |
Correct |
5 |
Correct |
26 ms |
932 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
10 ms |
348 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Incorrect |
19 ms |
600 KB |
Unexpected end of file - int32 expected |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
78 ms |
420 KB |
Correct |
4 |
Correct |
12 ms |
452 KB |
Correct |
5 |
Correct |
131 ms |
440 KB |
Correct |
6 |
Correct |
140 ms |
452 KB |
Correct |
7 |
Correct |
1 ms |
348 KB |
Correct |
8 |
Correct |
90 ms |
344 KB |
Correct |
9 |
Correct |
108 ms |
444 KB |
Correct |
10 |
Correct |
137 ms |
344 KB |
Correct |
11 |
Correct |
21 ms |
348 KB |
Correct |
12 |
Correct |
137 ms |
344 KB |
Correct |
13 |
Correct |
171 ms |
440 KB |
Correct |
14 |
Correct |
9 ms |
348 KB |
Correct |
15 |
Correct |
24 ms |
464 KB |
Correct |
16 |
Correct |
32 ms |
452 KB |
Correct |
17 |
Correct |
23 ms |
456 KB |
Correct |
18 |
Correct |
16 ms |
344 KB |
Correct |
19 |
Correct |
1 ms |
344 KB |
Correct |
20 |
Correct |
1 ms |
504 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Incorrect |
38 ms |
600 KB |
Unexpected end of file - int32 expected |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
20 ms |
856 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
26 ms |
756 KB |
Correct |
6 |
Correct |
26 ms |
932 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
10 ms |
348 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Incorrect |
19 ms |
600 KB |
Unexpected end of file - int32 expected |
12 |
Halted |
0 ms |
0 KB |
- |