#include <bits/stdc++.h>
using namespace std;
vector<int> in_between;
bool possible(int K, vector<int> (&sprinks), vector<int> (&flowers))
{
int N = sprinks.size();
int M = flowers.size();
int covered = -1;
int towater = 0;
int i = 0;
while (i<N)
{
if (towater<M)
{
int loc = sprinks[i];
if (flowers[towater]<loc)
{
if (flowers[towater] < (loc-K))
return 0;
if (((i+1)<N) and (flowers[towater] >= (sprinks[i+1]-K)) and (in_between[i]>0))
{
i++;
covered = loc+K;
}
else
covered = loc;
}
else
covered = loc+K;
while ((towater<M) and (flowers[towater]<=covered))
towater++;
}
i++;
}
if (towater==M)
return 1;
return 0;
}
/*int seed=525697;
int rando(int a, int b)
{
seed += a;
seed = b*seed;
seed = (seed*seed*seed + seed*seed*3 + 200*seed*seed*seed*b*seed + a*a*a);
seed = abs(seed);
int beed = seed%(b-a+1);
return a + beed;
}
void check(int j)
{
vector<int> spri;
vector<int> flow;
for (int i=0; i<10000; i++)
{
int k = rando(8, 170108);
spri.push_back(k);
if ((rando(1, 2)==1))
{
for (int j=0; j<rando(1, 8); j++)
flow.push_back(rando(k-8, k));
}
else
{
for (int j=0; j<rando(1, 8); j++)
flow.push_back(rando(k, k+8));
}
}
sort(spri.begin(), spri.end());
sort(flow.begin(), flow.end());
if (!possible(8, spri, flow))
cout << "alert!!!" << j << '\n';
else
seed = 7812364+j*j*j*seed+seed*seed+5*seed+(seed%27263);
}*/
void report(int K, vector<int> (&sprinks), vector<int> (&flowers))
{
cout << K << '\n';
int N = sprinks.size();
int M = flowers.size();
int covered = -1;
int towater = 0;
int i = 0;
while (i<N)
{
if (towater<M)
{
int loc = sprinks[i];
if (flowers[towater]<loc)
{
if (((i+1)<N) and (flowers[towater] >= (sprinks[i+1]-K)) and (in_between[i]>0))
{
i++;
covered = loc+K;
cout << "RL";
}
else
{
covered = loc;
cout << 'L';
}
}
else
{
covered = loc+K;
cout << 'R';
}
while ((towater<M) and (flowers[towater]<=covered))
towater++;
}
else
cout << 'R';
i++;
}
cout << '\n';
}
int main()
{
int N, M;
cin >> N >> M;
vector<int> sprinks(N);
vector<int> flowers(M);
for (int i=0; i<N; i++)
cin >> sprinks[i];
for (int i=0; i<M; i++)
cin >> flowers[i];
if (N==1)
{
int left = flowers[0]-sprinks[0];
int righ = flowers[M-1]-sprinks[0];
if ((left<0) and (righ>0))
cout << "-1\n";
else
{
cout << max(abs(left), abs(righ)) << '\n';
if (left<0)
cout << "L\n";
else
cout << "R\n";
}
}
else
{
in_between = vector<int> (N-1, 0);
int curr = 0;
for (int i=0; i<M; i++)
{
while (((curr+1)<N) and (flowers[i]>=sprinks[curr+1]))
curr++;
if (((curr+1)<N) and (flowers[i]>sprinks[curr]) and (flowers[i]<sprinks[curr+1]))
in_between[curr]++;
}
bool tapos = 0;
for (int guess = 0; guess<=8; guess++)
{
if ((!tapos) and possible(guess, sprinks, flowers))
{
report(guess, sprinks, flowers);
tapos = 1;
}
}
if (!tapos)
report(8, sprinks, flowers);
//for (int i=0; i<(N-1); i++)
//cout << in_between[i] << '\n';
/*int lo = 0;
int hi = 1'000'000'005;
while (lo!=hi)
{
int mid = (lo+hi)/2;
if (possible(mid, sprinks, flowers))
hi = mid;
else
lo = mid+1;
}
report(lo, sprinks, flowers);*/
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
31 ms |
748 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
29 ms |
604 KB |
Correct |
5 |
Correct |
29 ms |
832 KB |
Correct |
6 |
Correct |
1 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
8 ms |
508 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Incorrect |
30 ms |
844 KB |
User solution is incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Incorrect |
1 ms |
348 KB |
User solution is incorrect |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
31 ms |
860 KB |
Correct |
3 |
Correct |
62 ms |
1596 KB |
Correct |
4 |
Correct |
70 ms |
1460 KB |
Correct |
5 |
Correct |
64 ms |
1460 KB |
Correct |
6 |
Correct |
75 ms |
1484 KB |
Correct |
7 |
Correct |
58 ms |
1456 KB |
Correct |
8 |
Correct |
59 ms |
1480 KB |
Correct |
9 |
Correct |
74 ms |
1620 KB |
Correct |
10 |
Correct |
72 ms |
1476 KB |
Correct |
11 |
Correct |
87 ms |
1480 KB |
Correct |
12 |
Correct |
1 ms |
348 KB |
Correct |
13 |
Correct |
0 ms |
348 KB |
Correct |
14 |
Correct |
40 ms |
1104 KB |
Correct |
15 |
Correct |
27 ms |
1104 KB |
Correct |
16 |
Correct |
27 ms |
1100 KB |
Correct |
17 |
Correct |
24 ms |
1620 KB |
Correct |
18 |
Correct |
51 ms |
1616 KB |
Correct |
19 |
Correct |
42 ms |
1620 KB |
Correct |
20 |
Correct |
45 ms |
1472 KB |
Correct |
21 |
Correct |
46 ms |
1616 KB |
Correct |
22 |
Correct |
45 ms |
1620 KB |
Correct |
23 |
Incorrect |
44 ms |
1620 KB |
User solution is incorrect |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
31 ms |
748 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
29 ms |
604 KB |
Correct |
6 |
Correct |
29 ms |
832 KB |
Correct |
7 |
Correct |
1 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
8 ms |
508 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Incorrect |
30 ms |
844 KB |
User solution is incorrect |
12 |
Halted |
0 ms |
0 KB |
- |