답안 #1059196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059196 2024-08-14T18:29:38 Z vjudge1 구경하기 (JOI13_watching) C++17
0 / 100
5 ms 724 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;
            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;
            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;
    }
}

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:108:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  108 |     for(long long 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(long long int, std::vector<long long int>*, std::vector<long long int>*, long long int, long long int, long long int, std::vector<long long int>)':
watching.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type]
   57 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -