Submission #132810

# Submission time Handle Problem Language Result Execution time Memory
132810 2019-07-19T16:02:58 Z miguel Watching (JOI13_watching) C++14
100 / 100
425 ms 31864 KB
#include<bits/stdc++.h>
//#include<gondola.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define int ll
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <int, pi>
#define vi vector <int>
const ll mod = 998244353;
int n, p, q, dp[2005][2005];
int w[2005];

bool check(int d){
    for(int i=0; i<=n; i++){
        for(int j=0; j<=p; j++) dp[i][j]=1e18;
    }
    dp[0][0]=0;
    for(int j=1; j<=p; j++) dp[0][j]=0;
    for(int i=0; i<n; i++){
        int x=(upper_bound(w+1, w+n+1, w[i+1]+d-1)-w)-1;
        int y=(upper_bound(w+1, w+n+1, w[i+1]+2*d-1)-w)-1;
        for(int j=0; j<=p; j++){
            if(j<p) dp[x][j+1]=min(dp[x][j+1], dp[i][j]);
            dp[y][j]=min(dp[y][j], dp[i][j]+1);
        }
    }
    /*if(d<=8)cout<<d<<"\n";
    if(d<=8){
        for(int i=0; i<=n; i++){
            for(int j=0; j<=p; j++){
                cout<<dp[i][j]<<" ";
            }cout<<endl;
        }
        cout<<endl;
    }*/
    return (dp[n][p]<=q);
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>p>>q;
    p=min(p, n);
    for(int i=1; i<=n; i++){
        cin>>w[i];
    }
    int l=0, r=1e9+1;
    sort(w+1, w+n+1);
    //w.pb(1000000001);
    while(r-l>1){
        int mid=(l+r)>>1;
        if(check(mid)) r=mid;
        else l=mid;
    }
    cout<<r;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 888 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 3 ms 888 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8516 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 338 ms 31736 KB Output is correct
4 Correct 425 ms 31864 KB Output is correct
5 Correct 38 ms 9692 KB Output is correct
6 Correct 424 ms 31864 KB Output is correct
7 Correct 17 ms 8696 KB Output is correct
8 Correct 38 ms 10360 KB Output is correct
9 Correct 162 ms 20316 KB Output is correct
10 Correct 424 ms 31736 KB Output is correct
11 Correct 33 ms 9848 KB Output is correct
12 Correct 216 ms 23800 KB Output is correct
13 Correct 24 ms 8696 KB Output is correct
14 Correct 23 ms 8696 KB Output is correct
15 Correct 21 ms 8696 KB Output is correct