# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43806 | top34051 | Watching (JOI13_watching) | C++14 | 329 ms | 16324 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e3 + 5;
int n,p,q;
vector<ll> t;
ll a[maxn];
int warp1[maxn], warp2[maxn];
int dp[maxn][maxn];
int solve(int w) {
for(int x=1,y1=1,y2=1;x<=n;x++) {
while(y1<=n && a[x] + w > a[y1]) y1++;
while(y2<=n && a[x] + w*2 > a[y2]) y2++;
warp1[x] = y1; warp2[x] = y2;
}
for(int x=n;x>=1;x--) {
for(int i=0;i<=p;i++) {
dp[x][i] = dp[warp2[x]][i] + 1;
if(i) dp[x][i] = min(dp[x][i], dp[warp1[x]][i-1]);
}
}
return dp[1][p]<=q;
}
int main() {
scanf("%d%d%d",&n,&p,&q);
for(int i=1;i<=n;i++) {
ll x;
scanf("%lld",&x);
t.push_back(x);
}
sort(t.begin(),t.end());
t.erase(unique(t.begin(),t.end()),t.end());
n = (int)t.size();
for(int i=1;i<=n;i++) a[i] = t[i-1];
//fuck you
if(p+q>=n) return !printf("1");
//solve
ll l = 0, r = 2e9, mid, res;
while(l<=r) {
mid = (l+r)/2;
if(solve(mid)) res = mid, r = mid-1;
else l = mid+1;
}
printf("%lld",res);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |