답안 #1114758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114758 2024-11-19T14:38:40 Z Newtonabc 구경하기 (JOI13_watching) C++14
0 / 100
504 ms 31312 KB
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+10;
int dp[N][N],arr[N];
int main(){
    int n,p,q;
    cin>>n >>p >>q;
    for(int i=1;i<=n;i++) cin>>arr[i];
    arr[n+1]=INT_MAX;
    sort(arr+1,arr+n+1);
    int l=0,r=1e9;
    while(l<r){
        int w=(l+r)/2;
        for(int i=0;i<=p;i++) for(int j=0;j<=q;j++) dp[i][j]=0;
        for(int i=0;i<=min(p,n);i++){
            for(int j=0;j<=min(q,n);j++){
                if(i) dp[i][j]=max(dp[i][j],dp[i-1][j]);
                if(j) dp[i][j]=max(dp[i][j],dp[i][j-1]);
                if(dp[i][j]==n) continue;
                if(i) dp[i][j]=max(dp[i][j],dp[i-1][j]+(int)(upper_bound(arr+dp[i-1][j]+1,arr+n+2,w+arr[dp[i-1][j]+1]-1)-(arr+dp[i-1][j]+1)));
                if(j) dp[i][j]=max(dp[i][j],dp[i][j-1]+(int)(upper_bound(arr+dp[i][j-1]+1,arr+n+2,2*w+arr[dp[i][j-1]+1]-1)-(arr+dp[i][j-1]+1)));
            }
        }
        if(dp[min(p,n)][min(q,n)]==n) r=w;
        else l=w+1;
        /*cout<<w <<"\n";
        for(int i=0;i<=p;i++){
            for(int j=0;j<=q;j++){
                cout<<dp[i][j] <<" ";
            }
            cout<<"\n";
        }*/
    }
    cout<<l;
    
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Runtime error 23 ms 31056 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 504 ms 12928 KB Output is correct
4 Runtime error 25 ms 31312 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -