# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
172373 | 79brue | Mountains (IOI17_mountains) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}