| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 406026 | tqbfjotld | The short shank; Redemption (BOI21_prison) | C++14 | 77 ms | 8276 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 int long long
int range_len[2000005];
pair<int,int> memo[2005][2005];
int N,D,T;
pair<int,int> operator+ (pair<int,int> a, pair<int,int> b){
return {a.first+b.first,a.second+b.second};
}
pair<int,int> solve(int K){
for (int x = 0; x<=N; x++){
memo[N][x] = {0,0};
}
for (int x = N-1; x>=0; x--){
for (int o = 0; o<=N; o++){
memo[x][o] = memo[x+1][0]+make_pair(K+(range_len[x]>0),1);
if (o>range_len[x]) memo[x][o] = min(memo[x][o],memo[x+1][o-1]+make_pair(1,0));
else memo[x][o] = min(memo[x][o],memo[x+1][max(0LL,range_len[x]-1)]+make_pair((range_len[x]>0),0));
//printf("ans %lld %lld = %lld,%lld\n",x,o,memo[x][o]);
}
}
return memo[0][0];
}
main(){
scanf("%lld%lld%lld",&N,&D,&T);
for (int x = 0; x<N; x++){
int a;
scanf("%lld",&a);
range_len[x] = T-a+1;
if (range_len[x]<0) range_len[x] = 0;
if (x+range_len[x]>N) range_len[x] = N-x;
}
int a = -1;
int b = N;
while (a+1<b){
//printf("try %lld\n",(a+b)/2);
if (solve((a+b)/2).second>D){
a = (a+b)/2;
}
else b = (a+b)/2;
}
pair<int,int> res = solve(b);
//printf("b = %lld, res = %lld %lld\n",b,res);
printf("%lld",res.first-res.second*b-b*(D-res.second));
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
