답안 #1072671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072671 2024-08-24T02:21:06 Z jer033 Sprinklers (CEOI24_sprinklers) C++17
26 / 100
92 ms 3500 KB
#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;
}

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]++;
        }
        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 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 604 KB Correct
3 Correct 0 ms 600 KB Correct
4 Correct 24 ms 604 KB Correct
5 Correct 29 ms 604 KB Correct
6 Correct 0 ms 344 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 5 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 26 ms 604 KB Correct
3 Correct 5 ms 348 KB Correct
4 Correct 61 ms 1664 KB Correct
5 Correct 63 ms 1472 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 53 ms 1460 KB Correct
9 Correct 53 ms 1616 KB Correct
10 Correct 62 ms 1616 KB Correct
11 Correct 31 ms 1104 KB Correct
12 Correct 37 ms 1108 KB Correct
13 Correct 42 ms 1348 KB Correct
14 Correct 48 ms 1348 KB Correct
15 Correct 49 ms 1368 KB Correct
16 Correct 41 ms 1372 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 1 ms 348 KB Correct
5 Correct 1 ms 348 KB Correct
6 Correct 1 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 1 ms 348 KB Correct
10 Correct 1 ms 348 KB Correct
11 Correct 1 ms 348 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 1 ms 348 KB Correct
14 Correct 0 ms 348 KB Correct
15 Correct 1 ms 348 KB Correct
16 Correct 0 ms 344 KB Correct
17 Correct 0 ms 348 KB Correct
18 Correct 0 ms 348 KB Correct
19 Correct 1 ms 348 KB Correct
20 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 31 ms 860 KB Correct
3 Correct 77 ms 1616 KB Correct
4 Correct 92 ms 3412 KB Correct
5 Correct 79 ms 3408 KB Correct
6 Correct 84 ms 3500 KB Correct
7 Correct 79 ms 3376 KB Correct
8 Correct 78 ms 3408 KB Correct
9 Correct 76 ms 3412 KB Correct
10 Correct 79 ms 3392 KB Correct
11 Correct 77 ms 3408 KB Correct
12 Correct 0 ms 344 KB Correct
13 Correct 0 ms 344 KB Correct
14 Correct 35 ms 2136 KB Correct
15 Correct 35 ms 2132 KB Correct
16 Correct 34 ms 2136 KB Correct
17 Correct 27 ms 2188 KB Correct
18 Correct 34 ms 2388 KB Correct
19 Correct 39 ms 2644 KB Correct
20 Correct 65 ms 3000 KB Correct
21 Correct 77 ms 3152 KB Correct
22 Correct 56 ms 2896 KB Correct
23 Incorrect 60 ms 2896 KB User solution is worse than jury's solution
24 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 604 KB Correct
4 Correct 0 ms 600 KB Correct
5 Correct 24 ms 604 KB Correct
6 Correct 29 ms 604 KB Correct
7 Correct 0 ms 344 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 5 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 26 ms 604 KB Correct
12 Correct 5 ms 348 KB Correct
13 Correct 61 ms 1664 KB Correct
14 Correct 63 ms 1472 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 53 ms 1460 KB Correct
18 Correct 53 ms 1616 KB Correct
19 Correct 62 ms 1616 KB Correct
20 Correct 31 ms 1104 KB Correct
21 Correct 37 ms 1108 KB Correct
22 Correct 42 ms 1348 KB Correct
23 Correct 48 ms 1348 KB Correct
24 Correct 49 ms 1368 KB Correct
25 Correct 41 ms 1372 KB Correct
26 Correct 0 ms 348 KB Correct
27 Correct 1 ms 348 KB Correct
28 Correct 1 ms 348 KB Correct
29 Correct 1 ms 348 KB Correct
30 Correct 0 ms 348 KB Correct
31 Correct 1 ms 348 KB Correct
32 Correct 1 ms 348 KB Correct
33 Correct 1 ms 348 KB Correct
34 Correct 1 ms 348 KB Correct
35 Correct 0 ms 348 KB Correct
36 Correct 1 ms 348 KB Correct
37 Correct 0 ms 348 KB Correct
38 Correct 1 ms 348 KB Correct
39 Correct 0 ms 344 KB Correct
40 Correct 0 ms 348 KB Correct
41 Correct 0 ms 348 KB Correct
42 Correct 1 ms 348 KB Correct
43 Correct 0 ms 348 KB Correct
44 Correct 31 ms 860 KB Correct
45 Correct 77 ms 1616 KB Correct
46 Correct 92 ms 3412 KB Correct
47 Correct 79 ms 3408 KB Correct
48 Correct 84 ms 3500 KB Correct
49 Correct 79 ms 3376 KB Correct
50 Correct 78 ms 3408 KB Correct
51 Correct 76 ms 3412 KB Correct
52 Correct 79 ms 3392 KB Correct
53 Correct 77 ms 3408 KB Correct
54 Correct 0 ms 344 KB Correct
55 Correct 0 ms 344 KB Correct
56 Correct 35 ms 2136 KB Correct
57 Correct 35 ms 2132 KB Correct
58 Correct 34 ms 2136 KB Correct
59 Correct 27 ms 2188 KB Correct
60 Correct 34 ms 2388 KB Correct
61 Correct 39 ms 2644 KB Correct
62 Correct 65 ms 3000 KB Correct
63 Correct 77 ms 3152 KB Correct
64 Correct 56 ms 2896 KB Correct
65 Incorrect 60 ms 2896 KB User solution is worse than jury's solution
66 Halted 0 ms 0 KB -