Submission #1059198

# Submission time Handle Problem Language Result Execution time Memory
1059198 2024-08-14T18:30:55 Z vjudge1 Watching (JOI13_watching) C++17
50 / 100
91 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

bool check(long long w,vector<long long> dp1[],vector<long long> dp2[],long long n,long long p,long long q,vector<long long> vec)
{

    dp1[0][p]=q;
    dp2[0][q]=p;
    vec.push_back(2000000000);

    for(long long i=0;i<n;i++)
    {
        for(long long j=p;j>0;j--)
        {
            long long br=vec[i]+w-1;
            for(long long k=i+1;k<=n;k++)
            {

                if(vec[k]>br)
                {
                    dp1[k][j-1]=max(dp1[k][j-1],dp1[i][j]);
                    dp2[k][dp1[i][j]]=max(dp2[k][dp1[i][j]],j-1);
                    break;
                }
            }
        }

        for(long long j=q;j>0;j--)
        {
            long long br=vec[i]+2*w-1;
            for(long long k=i+1;k<=n;k++)
            {
                if(vec[k]>br)
                {
                    dp2[k][j-1]=max(dp2[k][j-1],dp2[i][j]);
                    dp1[k][dp2[i][j]]=max(dp1[k][dp2[i][j]],j-1);
                    break;
                }
            }
        }

    }

    for(long long i=p;i>=0;i--)
    {

        if(dp1[n][i]!=-1)
            return true;

    }
    for(long long i=q;i>=0;i--)
    {
        if(dp2[n][i]!=-1)
            return true;
    }
    return false;
}

int main()
{
    long long n,p,q;
    cin>>n>>p>>q;
    vector<long long> vec;
    for(long long n1=n;n1>0;n1--)
    {
        long long x;
        cin>>x;
        vec.push_back(x);
    }
    sort(vec.begin(),vec.end());
    vector<long long> dp1[n+1];
    vector<long long> temp;
    for(long long i=p;i>=0;i--)
    {
        temp.push_back(-1);
    }
    for(long long i=0;i<=n;i++)
        dp1[i]=(temp);
    vector<long long> dp2[n+1];
     temp.clear();
    for(long long i=q;i>=0;i--)
    {
        temp.push_back(-1);
    }
    for(long long i=0;i<=n;i++)
        dp2[i]=(temp);
    if(p+q>=n)
    {
        cout<<1;
        return 0;
    }
    long long l=1,r=1000000000;
    long long m=(l+r)/2;
    for(;l<=r;m=(l+r)/2)
    {
    temp.clear();
    for(long long i=p;i>=0;i--)
    {
        temp.push_back(-1);
    }
    for(long long i=0;i<=n;i++)
        dp1[i]=(temp);
     temp.clear();
    for(long long i=q;i>=0;i--)
    {
        temp.push_back(-1);
    }
    for(long long i=0;i<=n;i++)
        dp2[i]=(temp);



        bool pos=check(m,dp1,dp2,n,p,q,vec);


    if(pos==false)
    {
        l=m+1;
    }
    else
        r=m-1;
    }
    cout<<l;

}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:109:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  109 |     for(long long i=0;i<=n;i++)
      |     ^~~
watching.cpp:114:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  114 |         bool pos=check(m,dp1,dp2,n,p,q,vec);
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 32 ms 80516 KB Output is correct
5 Correct 27 ms 80588 KB Output is correct
6 Correct 53 ms 159944 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 17 ms 47452 KB Output is correct
4 Runtime error 91 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -