제출 #21050

#제출 시각아이디문제언어결과실행 시간메모리
21050sbansalcs구경하기 (JOI13_watching)C++14
50 / 100
1000 ms17676 KiB
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 2001;
ll arr[N];
int dp[N][N];
int n,p,q;

bool check(ll w)   {
    for (int i=n+1; i>=1; i--) {
        for (int j=0; j<=q; j++) {
            if(i==n+1)  dp[i][j]=0;
            else    {
                ll a;
                a=arr[i]+w;
                int lx=i+1,rx=n+1,mx;
                while (lx<rx) {
                    mx= (lx+rx)/2;
                    if(arr[mx]>=a)  rx=mx;
                    else    lx=mx+1;
                }
                dp[i][j]=1+dp[lx][j];
                if(j!=0)    {
                    a=arr[i]+2*w;
                    int lx=i+1,rx=n+1,mx;
                    while (lx<rx) {
                        mx= (lx+rx)/2;
                        if(arr[mx]>=a)  rx=mx;
                        else    lx=mx+1;
                    }
                    dp[i][j]=min(dp[i][j],dp[lx][j-1]);
                    dp[i][j]=min(dp[i][j],dp[i][j-1]);
                }
            }
        }
    }
    return dp[1][q]<=p;
}

int main() {
    scanf("%d %d %d",&n,&p,&q);
    for (int i=1; i<=n; i++) {
        scanf("%lld",arr+i);
    }
    if(p+q>=n)  {
        cout<<1<<endl;return 0;
    }
    sort(arr+1,arr+1+n);
    arr[n+1]=2e9;
    int lx=1,rx=1e9,mx;
    while (lx<rx) {
        mx=(lx+rx)/2;
        if(check(mx))   rx=mx;
        else    lx=mx+1;
    }
    cout<<lx<<endl;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'int main()':
watching.cpp:42:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&n,&p,&q);
                               ^
watching.cpp:44:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",arr+i);
                            ^

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...