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[4005][4005];
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)
prison.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
28 | main(){
| ^~~~
prison.cpp: In function 'int main()':
prison.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%lld%lld%lld",&N,&D,&T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
prison.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
# | 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... |