Submission #1074922

# Submission time Handle Problem Language Result Execution time Memory
1074922 2024-08-25T16:39:31 Z raphaelp Sprinklers (CEOI24_sprinklers) C++14
9 / 100
253 ms 9368 KB
#include <bits/stdc++.h>
using namespace std;
bool solve(vector<int> &S, vector<int> &F, int K, vector<int> &ans)
{
    int N = S.size(), M = F.size();
    S.push_back(2000000001);
    ans.assign(N, 0);
    int buff = 0;
    bool b = 0;
    vector<int> next(N + 1), prev(N + 1), nextsprinkle(M + 1, N), after(N + 1);
    next[N] = M;
    prev[N] = M;
    after[N] = M;
    nextsprinkle[M] = N;
    for (int i = 0; i < N; i++)
    {
        while (buff < M && F[buff] < S[i])
        {
            nextsprinkle[buff] = i;
            buff++;
        }
        prev[i] = buff - 1;
        next[i] = buff;
    }
    buff = 0;
    for (int i = 0; i < N; i++)
    {
        while (buff < M && F[buff] - K <= S[i])
            buff++;
        after[i] = buff;
    }
    buff = 0;
    vector<int> sprinkle, done(M + 1);
    done[M] = 1;
    int cover = -1000000001;
    for (int i = 0; i < N; i++)
    {
        while (buff < M && F[buff] < S[i])
        {
            if (cover + K < F[buff])
                b = 0;
            else
                done[buff] = 1;
            buff++;
        }
        if (prev[i] == -1 || F[prev[i]] + K < S[i] || b == 1)
        {
            ans[i] = 1;
            sprinkle.push_back(S[i]);
            cover = S[i];
            b = 1;
        }
        if (next[i] == M || F[next[i]] - K > S[i])
        {
            ans[i] = -1;
            sprinkle.push_back(S[i] - K);
        }
        if (i > 0 && (prev[i] == -1 || S[i - 1] > F[prev[i]]))
        {
            ans[i] = 1;
            sprinkle.push_back(S[i]);
            cover = S[i];
            b = 1;
            ans[i - 1] = -1;
            sprinkle.push_back(S[i - 1] - K);
        }
    }
    while (buff < M)
    {
        if (cover + K < F[buff])
            b = 0;
        else
            done[buff] = 1;
        buff++;
    }
    buff = M - 1;
    b = 0;
    cover = 2000000001;
    for (int i = N - 1; i >= 0; i--)
    {
        while (buff >= 0 && F[buff] > S[i])
        {
            if (cover - K > F[buff])
                b = 0;
            else
                done[buff] = 1;
            buff--;
        }
        if (b == 1)
        {
            cover = S[i];
            sprinkle.push_back(S[i] - K);
            ans[i] = -1;
        }
        if (ans[i] == -1)
        {
            cover = S[i];
            b = 1;
        }
    }
    while (buff >= 0)
    {
        if (cover - K > F[buff])
            b = 0;
        else
            done[buff] = 1;
        buff--;
    }
    vector<pair<int, int>> dp(M);
    int donext = 0;
    for (int i = 0; i < M; i++)
    {
        if (done[i])
            continue;
        if (donext <= i)
        {
            dp[i].first = 1;
            donext = M + 10;
        }
        if (dp[i].first == 0)
            continue;
        if (S[nextsprinkle[i]] - K <= F[i])
        {
            if (done[next[nextsprinkle[i]]])
            {
                donext = next[nextsprinkle[i]];
            }
            dp[next[nextsprinkle[i]]].first = 1;
            if (S[nextsprinkle[i] + 1] - K <= F[i])
            {
                if (done[after[nextsprinkle[i]]])
                {
                    donext = after[nextsprinkle[i]];
                }
                dp[after[nextsprinkle[i]]].first = 1;
            }
        }
        if (dp[i].second == 1)
        {
            if (done[after[nextsprinkle[i] - 1]])
            {
                donext = after[nextsprinkle[i] - 1];
            }
            dp[after[nextsprinkle[i] - 1]].first = 1;
            if (F[after[nextsprinkle[i] - 1]] > S[nextsprinkle[i]])
                dp[after[nextsprinkle[i] - 1]].second = 1;
        }
    }
    S.pop_back();
    if (donext != M + 10)
        return 1;
    else
        return 0;
}
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> S(N), F(M), F2;
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
    }
    for (int i = 0; i < M; i++)
    {
        cin >> F[i];
    }
    int buff = 0;
    for (int i = 0; i < N; i++)
    {
        while (buff < M && F[buff] <= S[i])
        {
            if (F[buff] != S[i])
                F2.push_back(F[buff]);
            buff++;
        }
    }
    while (buff < M)
        F2.push_back(F[buff++]);
    swap(F, F2);
    if (N == 1 && F[0] < S[0] && F[M - 1] > S[0])
    {
        cout << -1;
        return 0;
    }
    int L = 0, R = 1000000000;
    vector<int> ans(N);
    while (L != R)
    {
        int m = (L + R) / 2;
        if (solve(S, F, m, ans))
            R = m;
        else
            L = m + 1;
    }
    bool b = solve(S, F, L, ans);
    cout << L << endl;
    for (int i = 0; i < N; i++)
        cout << ((ans[i] == 1) ? 'R' : 'L');
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:196:10: warning: unused variable 'b' [-Wunused-variable]
  196 |     bool b = solve(S, F, L, ans);
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 41 ms 3284 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 24 ms 2220 KB Correct
5 Correct 25 ms 2252 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 5 ms 704 KB Correct
9 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 49 ms 3856 KB Correct
3 Correct 18 ms 1116 KB Correct
4 Correct 200 ms 9368 KB Correct
5 Correct 189 ms 9344 KB Correct
6 Correct 0 ms 344 KB Correct
7 Correct 0 ms 344 KB Correct
8 Correct 157 ms 8644 KB Correct
9 Correct 150 ms 8716 KB Correct
10 Correct 183 ms 9176 KB Correct
11 Correct 139 ms 7404 KB Correct
12 Correct 92 ms 5592 KB Correct
13 Correct 169 ms 7820 KB Correct
14 Correct 183 ms 8176 KB Correct
15 Correct 190 ms 8288 KB Correct
16 Correct 155 ms 7584 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 1 ms 344 KB Correct
2 Correct 70 ms 3920 KB Correct
3 Incorrect 253 ms 8976 KB User solution is incorrect
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 41 ms 3284 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 24 ms 2220 KB Correct
6 Correct 25 ms 2252 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 5 ms 704 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 49 ms 3856 KB Correct
12 Correct 18 ms 1116 KB Correct
13 Correct 200 ms 9368 KB Correct
14 Correct 189 ms 9344 KB Correct
15 Correct 0 ms 344 KB Correct
16 Correct 0 ms 344 KB Correct
17 Correct 157 ms 8644 KB Correct
18 Correct 150 ms 8716 KB Correct
19 Correct 183 ms 9176 KB Correct
20 Correct 139 ms 7404 KB Correct
21 Correct 92 ms 5592 KB Correct
22 Correct 169 ms 7820 KB Correct
23 Correct 183 ms 8176 KB Correct
24 Correct 190 ms 8288 KB Correct
25 Correct 155 ms 7584 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 -