Submission #77439

# Submission time Handle Problem Language Result Execution time Memory
77439 2018-09-27T20:24:30 Z Vardanyan Watching (JOI13_watching) C++14
0 / 100
450 ms 32240 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int a[N];
int mxshort[N];
int mxlong[N];
int dp[N][N];
int main(){
    int n,p,q;
    scanf("%d%d%d",&n,&p,&q);
    for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int l = 1;
    int r = 1000*1000*1000;
    int ans = r;
    while(l<=r){
        int m = (l+r)/2;
        memset(mxlong,0,sizeof(mxlong));
        memset(mxshort,0,sizeof(mxshort));
        memset(dp,0,sizeof(dp));
        int now = n;
        int noww = n;
        for(int i = n;i>=1;i--){
            while(!(abs(a[i]-a[now])+1<=m)) now--;
            mxshort[i] = now;
            while(!(abs(a[i]-a[noww])+1<=2*m)) noww--;
            mxlong[i] = noww;
        }
        bool f = false;
        dp[0][0] = 1;
        int u = 5;
        for(int i = 0;i<=min(n,p);i++){
            for(int j = 0;j<=min(n,q);j++){
                int pos = max(1,dp[i][j]);
                dp[i+1][j] = max(dp[i+1][j],mxshort[pos]+1);
                dp[i][j+1] = max(dp[i][j+1],mxlong[pos]+1);
            }
        }

        for(int i = 0;i<=p;i++){
            for(int j = 0;j<=q;j++) if(dp[i][j]>n) f = true;
        }
        if(f){
            ans = m;
            r = m-1;
        }
        else l = m+1;
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:31:13: warning: unused variable 'u' [-Wunused-variable]
         int u = 5;
             ^
watching.cpp:10:10: 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:11:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
                             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 42 ms 16120 KB Output is correct
2 Correct 43 ms 16128 KB Output is correct
3 Correct 41 ms 16184 KB Output is correct
4 Runtime error 35 ms 31988 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 32120 KB Output is correct
2 Correct 41 ms 32120 KB Output is correct
3 Correct 450 ms 32196 KB Output is correct
4 Runtime error 39 ms 32240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -