Submission #1059191

# Submission time Handle Problem Language Result Execution time Memory
1059191 2024-08-14T18:26:35 Z vjudge1 Watching (JOI13_watching) C++17
0 / 100
4 ms 696 KB
#include <bits/stdc++.h>

using namespace std;

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

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

    for(int i=0;i<n;i++)
    {
        for(int j=p;j>0;j--)
        {
            int br=vec[i]+w-1;
            for(int 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(int j=q;j>0;j--)
        {
            int br=vec[i]+2*w-1;
            for(int 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(int i=p;i>=0;i--)
    {

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

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

int main()
{
    int n,p,q;
    cin>>n>>p>>q;
    vector<int> vec;
    for(int n1=n;n1>0;n1--)
    {
        int x;
        cin>>x;
        vec.push_back(x);
    }
    sort(vec.begin(),vec.end());
    vector<int> dp1[n+1];
    vector<int> temp;
    for(int i=p;i>=0;i--)
    {
        temp.push_back(-1);
    }
    for(int i=0;i<=n;i++)
        dp1[i]=(temp);
    vector<int> dp2[n+1];
     temp.clear();
    for(int i=q;i>=0;i--)
    {
        temp.push_back(-1);
    }
    for(int i=0;i<=n;i++)
        dp2[i]=(temp);
    if(p+q>=n)
    {
        cout<<1;
        return 0;
    }
    int l=1,r=1000000000;
    int m=(l+r)/2;
    for(;l<=r;m=(l+r)/2)
    {
    temp.clear();
    for(int i=p;i>=0;i--)
    {
        temp.push_back(-1);
    }
    for(int i=0;i<=n;i++)
        dp1[i]=(temp);
     temp.clear();
    for(int i=q;i>=0;i--)
    {
        temp.push_back(-1);
    }
    for(int 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:108:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  108 |     for(int i=0;i<=n;i++)
      |     ^~~
watching.cpp:113:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  113 |         bool pos=check(m,dp1,dp2,n,p,q,vec);
      |         ^~~~
watching.cpp: In function 'bool check(int, std::vector<int>*, std::vector<int>*, int, int, int, std::vector<int>)':
watching.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type]
   57 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 696 KB Output isn't correct
2 Halted 0 ms 0 KB -