# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393692 | Qw3rTy | Rabbit Carrot (LMIO19_triusis) | C++11 | 1 ms | 332 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 <iostream>
#include <cstring>
using namespace std;
const int maxN = 2e5+5;
int a[maxN];
int f[maxN];
int dif[maxN];
int ps[maxN];
int N,M;
void testIO(){
freopen("../test.in","r",stdin);
return;
return;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//testIO();
cin >> N >> M;
for(int i = 1; i <= N; ++i)cin >> a[i];
int curHeight = M; //maximum previous height that can be reached
int prevHeight = M; //maximum current height that can be reached
for(int i = 1; i <= N; ++i){
//Can jump onto the next pole
if(a[i] <= curHeight){
dif[i] = 0;
//Moves forward
prevHeight = curHeight;
curHeight = a[i] + M;
}
else{
dif[i] = 1;
curHeight = max(prevHeight, curHeight); //Tries to go as high as possible
curHeight += M;
}
}
for(int i = 1; i <= N; ++i)ps[i] = ps[i-1] + dif[i];
for(int i = 1; i <= N; ++i){
for(int j = 0; j < i; ++j){
if(a[j] + M < a[i]){
f[i] = max(f[i],f[j] + ps[i] - ps[j-1]);
}
}
}
int res = 0;
for(int i = 1; i <= N; ++i)res = max(res,f[i]);
cout << res << '\n';
return 0;
}
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... |