# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
172373 | 79brue | Mountains (IOI17_mountains) | C++14 | 0 ms | 0 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;
typedef long long ll;
ll n;
ll arr[2002];
bool canSee[2002][2002];
ll DP[2002][2002];
ll ans;
int main(){
scanf("%lld", &n);
for(ll i=1; i<=n; i++) scanf("%lld", &arr[i]);
for(ll i=1; i<=n; i++){
ll x=1, y=-1e9-1;
for(ll j=i+1; j<=n; j++){
if(y*(j-i) <= x*(arr[j]-arr[i])){
canSee[i][j] = canSee[j][i] = 1;
x=j-i, y=arr[j]-arr[i];
}
}
}
for(ll j=1; j<=n; j++){
ll tmp = 1, l = 0;
DP[j][j] = 1;
for(ll i=j-1; i>=1; i--){
if(canSee[i][j]){
if(l) tmp += DP[i+1][l], l=0;
l = 0;
DP[i][j] = tmp;
}
else{
if(!l) l=i;
DP[i][j] = tmp + DP[i][l];
}
ans = max(ans, DP[i][j]);
// printf("%lld %lld: %lld\n", i, j, DP[i][j]);
}
}
printf("%lld", ans);
}