Submission #1074969

# Submission time Handle Problem Language Result Execution time Memory
1074969 2024-08-25T17:13:22 Z abouton Sprinklers (CEOI24_sprinklers) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

int S, F;
int kMin, kMax;
vector<int> sprink;
vector<int> fleurs;

int dernier; 
deque<int> poss;
int possibleS[100000+42];
int possibleF[100000+42];
bool directions[100000+42];
int parQui[100000+42];

int val(int a, int b)
{
    if (!b) return fleurs[a];
    return sprink[a];
}

struct objet
{
    int pos;
    int typ;
    bool operator<(const objet &autre) const
    {
        if (val(pos,typ) == val(autre.pos, autre.typ)) return typ < autre.typ;
        return val(pos,typ) < val(autre.pos, autre.typ);
    }
};
vector<objet> fusion;

bool tester(int k)
{
    for (int i = 0; i < S; i ++)
    {
        possibleS[i] = 0;
    }
    for (int i = 0; i < F; i ++)
    {
        possibleF[i] = 0;
    }
    poss.clear();
    //cout << "\n" << k << "\n";
    for (int i = fusion.size()-1; i >=0; i --)
    {
        int endr = val(fusion[i].pos, fusion[i].typ);

        int sorte = fusion[i].typ;
        int ind = fusion[i].pos;
        if (sorte == 1)
        {
            auto ans = upper_bound(fleurs.begin(), fleurs.end(), endr + k);
            if (ans == fleurs.end())
            {   
                possibleS[fusion[i].pos] = true;
            }
            else if (sprink[ind+1] <= fleurs[ans-fleurs.begin()])
            {
                possibleS[ind] = possibleS[ind+1];
            }
            else
            {
                possibleS[fusion[i].pos] = possibleF[ans - fleurs.begin()];
            }
            if (ind != S-1 && sprink[ind+1] <= sprink[ind]+k)
            {
                poss.push_back(ind+1);
            }
            dernier = fusion[i].pos;
            //cout << endr << ' ' << possibleS[fusion[i].pos]  << "\n";
        }

        if (sorte == 0)
        {
            while (!poss.empty() && sprink[poss.front()] > endr + k)
            {
                poss.pop_front();
            }
            if (dernier != 0)
            {
                if (sprink[dernier] <= endr+k)
                {
                    auto ans = upper_bound(fleurs.begin(), fleurs.end(), sprink[dernier]);
                    if (ans != fleurs.end() && possibleF[ans-fleurs.begin()])
                    {
                        possibleF[ind] = true;
                        parQui[ind] = dernier;
                    }
                }
            }
            if (!poss.empty())
            {
                possibleF[ind]= true;
                parQui[ind] = poss[0];
            }
            //cout << endr << ' ' << possibleF[ind] << "\n";
            //cout << "poss : ";
            //for (auto u : poss) cout << u << ' ';;
            //cout << '\n';
        }
    }
    //cout << possibleF[0];
    return possibleF[0];
}

int main()
{
    cin >> S >> F;
    sprink.resize(S);
    fleurs.resize(F);
    fusion.resize(S+F);
    for (int i = 0; i < S; i ++) {cin >> sprink[i]; fusion[i] = {i,1};}
    for (int i = 0; i <F; i ++) {cin >> fleurs[i]; fusion[i+S] = {i,0};}
    sort(fusion.begin(), fusion.end());
    kMin = 1;
    kMax = 1e9;
    while (kMin < kMax)
    {
        int k = kMin + (kMax-kMin)/2;
        if (tester(k))
        {
            kMax = k;
        }
        else
        {
            kMin = k+1;
        }
    }
    cout << kMin << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -