Submission #1072646

# Submission time Handle Problem Language Result Execution time Memory
1072646 2024-08-24T01:34:27 Z jer033 Sprinklers (CEOI24_sprinklers) C++17
9 / 100
72 ms 3256 KB
#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++;
        }
        else
            cout << 'R';
    }
    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
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 19 ms 604 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 23 ms 836 KB Correct
5 Correct 23 ms 604 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 1 ms 348 KB Correct
8 Correct 5 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 25 ms 1592 KB Correct
3 Correct 5 ms 604 KB Correct
4 Correct 64 ms 3156 KB Correct
5 Correct 65 ms 3028 KB Correct
6 Correct 0 ms 344 KB Correct
7 Correct 1 ms 348 KB Correct
8 Correct 57 ms 3136 KB Correct
9 Correct 58 ms 3120 KB Correct
10 Correct 58 ms 3152 KB Correct
11 Correct 32 ms 1876 KB Correct
12 Correct 35 ms 2136 KB Correct
13 Correct 41 ms 2172 KB Correct
14 Correct 55 ms 2388 KB Correct
15 Correct 47 ms 2384 KB Correct
16 Correct 39 ms 1972 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 348 KB Correct
3 Correct 1 ms 348 KB Correct
4 Correct 0 ms 348 KB Correct
5 Incorrect 1 ms 348 KB K is out of range
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 30 ms 1884 KB Correct
3 Incorrect 72 ms 3256 KB User solution is worse than jury's solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 348 KB Correct
3 Correct 19 ms 604 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 23 ms 836 KB Correct
6 Correct 23 ms 604 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 5 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 25 ms 1592 KB Correct
12 Correct 5 ms 604 KB Correct
13 Correct 64 ms 3156 KB Correct
14 Correct 65 ms 3028 KB Correct
15 Correct 0 ms 344 KB Correct
16 Correct 1 ms 348 KB Correct
17 Correct 57 ms 3136 KB Correct
18 Correct 58 ms 3120 KB Correct
19 Correct 58 ms 3152 KB Correct
20 Correct 32 ms 1876 KB Correct
21 Correct 35 ms 2136 KB Correct
22 Correct 41 ms 2172 KB Correct
23 Correct 55 ms 2388 KB Correct
24 Correct 47 ms 2384 KB Correct
25 Correct 39 ms 1972 KB Correct
26 Correct 1 ms 348 KB Correct
27 Correct 0 ms 348 KB Correct
28 Incorrect 1 ms 348 KB K is out of range
29 Halted 0 ms 0 KB -