이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
bool possible(int K, vector<int> (&sprinks), vector<int> (&flowers))
{
int N = sprinks.size();
int M = flowers.size();
int covered = -1;
int towater = 0;
for (int i=0; i<N; i++)
{
if (towater<M)
{
int loc = sprinks[i];
if (flowers[towater]<loc)
{
covered = loc;
if (flowers[towater] < (loc-K))
return 0;
}
else
covered = loc+K;
while ((towater<M) and (flowers[towater]<=covered))
towater++;
}
}
if (towater==M)
return 1;
return 0;
}
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;
for (int i=0; i<N; i++)
{
if (towater<M)
{
int loc = sprinks[i];
if (flowers[towater]<loc)
{
covered = loc;
cout << 'L';
}
else
{
covered = loc+K;
cout << 'R';
}
while ((towater<M) and (flowers[towater]<=covered))
towater++;
}
}
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
{
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);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |