#include <stdio.h>
#include <string.h>
#define N 100000
#define M 100000
#define X 1000000001
int max(int a, int b) { return a > b ? a : b; }
char cc[N + 1]; int xx[N + 2], yy[M], n, m;
int solve(int d) {
static int dp[N + 2], pp[N + 2];
int i, i_, i1, j, x, y;
memset(dp, -1, (n + 2) * sizeof *dp);
dp[0] = 0;
for (i = 0, i_ = 0, j = 0; i <= n; i++) {
if (dp[i] == -1)
return 0;
while (j < m && yy[j] < xx[i])
j++;
x = max(xx[i], xx[dp[i]] + d), y = -1;
while (j < m && yy[j] < xx[i + 1]) {
if (yy[j] > x) {
y = yy[j];
break;
}
j++;
}
if (y == -1)
dp[i + 1] = i + 1, pp[i + 1] = i;
else {
i_ = max(i_, i + 1);
while (i_ <= n + 1 && y >= xx[i_] - d) {
i1 = i_ == i + 1 ? dp[i] : i_ - 1;
if (dp[i_] < i1)
dp[i_] = i1, pp[i_] = i;
i_++;
}
}
}
if (dp[n + 1] == -1)
return 0;
i = n;
while (i > 0)
if (pp[i] == i - 1)
cc[i - 1] = dp[i] == i ? 'R' : 'L', i--;
else {
cc[--i] = 'L';
while (i > pp[i])
cc[--i] = 'R';
}
return 1;
}
int main() {
int m_, i, y, d, lower, upper;
scanf("%d%d", &n, &m);
xx[0] = -X - 1, xx[n + 1] = X * 2 + 1;
for (i = 1; i <= n; i++)
scanf("%d", &xx[i]);
m_ = 0, i = 0;
while (m--) {
scanf("%d", &y);
while (xx[i] < y)
i++;
if (xx[i] != y)
yy[m_++] = y;
}
m = m_;
lower = -1, upper = X;
while (upper - lower > 1) {
d = (lower + upper) / 2;
if (solve(d))
upper = d;
else
lower = d;
}
if (upper == X) {
printf("-1\n");
return 0;
}
solve(upper);
printf("%d\n", upper);
printf("%s\n", cc);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:60:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:63:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d", &xx[i]);
| ^~~~~~~~~~~~~~~~~~~
Main.c:66:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d", &y);
| ^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
8 ms |
1368 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
9 ms |
1636 KB |
Correct |
5 |
Correct |
19 ms |
1624 KB |
Correct |
6 |
Correct |
0 ms |
344 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
4 ms |
604 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
10 ms |
1628 KB |
Correct |
3 |
Correct |
3 ms |
600 KB |
Correct |
4 |
Correct |
31 ms |
4004 KB |
Correct |
5 |
Correct |
51 ms |
3924 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
1 ms |
348 KB |
Correct |
8 |
Correct |
25 ms |
3736 KB |
Correct |
9 |
Correct |
22 ms |
3676 KB |
Correct |
10 |
Correct |
42 ms |
3956 KB |
Correct |
11 |
Correct |
33 ms |
2660 KB |
Correct |
12 |
Correct |
32 ms |
2392 KB |
Correct |
13 |
Correct |
30 ms |
2908 KB |
Correct |
14 |
Correct |
56 ms |
3164 KB |
Correct |
15 |
Correct |
32 ms |
3356 KB |
Correct |
16 |
Correct |
33 ms |
2852 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
1 ms |
348 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Incorrect |
1 ms |
348 KB |
User solution is incorrect |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
14 ms |
1944 KB |
Correct |
3 |
Incorrect |
55 ms |
3948 KB |
User solution is incorrect |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
8 ms |
1368 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
9 ms |
1636 KB |
Correct |
6 |
Correct |
19 ms |
1624 KB |
Correct |
7 |
Correct |
0 ms |
344 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
4 ms |
604 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Correct |
10 ms |
1628 KB |
Correct |
12 |
Correct |
3 ms |
600 KB |
Correct |
13 |
Correct |
31 ms |
4004 KB |
Correct |
14 |
Correct |
51 ms |
3924 KB |
Correct |
15 |
Correct |
0 ms |
348 KB |
Correct |
16 |
Correct |
1 ms |
348 KB |
Correct |
17 |
Correct |
25 ms |
3736 KB |
Correct |
18 |
Correct |
22 ms |
3676 KB |
Correct |
19 |
Correct |
42 ms |
3956 KB |
Correct |
20 |
Correct |
33 ms |
2660 KB |
Correct |
21 |
Correct |
32 ms |
2392 KB |
Correct |
22 |
Correct |
30 ms |
2908 KB |
Correct |
23 |
Correct |
56 ms |
3164 KB |
Correct |
24 |
Correct |
32 ms |
3356 KB |
Correct |
25 |
Correct |
33 ms |
2852 KB |
Correct |
26 |
Correct |
1 ms |
348 KB |
Correct |
27 |
Correct |
0 ms |
348 KB |
Correct |
28 |
Incorrect |
1 ms |
348 KB |
User solution is incorrect |
29 |
Halted |
0 ms |
0 KB |
- |