Submission #724037

#TimeUsernameProblemLanguageResultExecution timeMemory
724037groshiSwimming competition (LMIO18_plaukimo_varzybos)C++17
100 / 100
419 ms22836 KiB
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> Q;
int n,a,b;
int mam[1200000];
bool git(int x)
{
    for(int i=0;i<=n;i++)
        mam[i]=0;
    int suma=1;
    mam[0]=1;
    int l=0,r=0;
    for(int i=1;i<=n;i++)
    {
        while(l<Q.size() && Q[l]+x<Q[i-1])
        {
            suma-=mam[l];
            l++;
        }
        while(r<Q.size() && Q[r]+x<Q[i-1])
        {
            suma+=mam[r+1];
            r++;
        }
        while(l+b<i)
        {
            suma-=mam[l];
            l++;
        }
        while(r+a<i)
        {
            suma+=mam[r+1];
            r++;
        }
        if(suma>0 && i-l>=a)
            mam[i]=1;
    }
    return mam[n];
}
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int x;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        Q.push_back(x);
    }
    sort(Q.begin(),Q.end());
    int pocz=0,kon=1e6,sre,ostd=1e9;
    while(pocz<kon)
    {
        sre=(pocz+kon)/2;
        if(git(sre))
        {
            ostd=sre;
            kon=sre;
        }
        else pocz=sre+1;
    }
    cout<<ostd;
    return 0;
}

Compilation message (stderr)

plaukimo_varzybos.cpp: In function 'bool git(long long int)':
plaukimo_varzybos.cpp:16:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         while(l<Q.size() && Q[l]+x<Q[i-1])
      |               ~^~~~~~~~~
plaukimo_varzybos.cpp:21:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         while(r<Q.size() && Q[r]+x<Q[i-1])
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...