#include"mountains.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 2010;
int y[N];
int f[N][N];
bool Judge(int a,int b,int c) { // a see c ?
// ((y[a] - y[b]) / (a - b)) > ((y[a] - y[c]) / (a - c));
return 1ll * (y[a] - y[b]) * (a - c) >= 1ll * (y[a] - y[c]) * (a - b);
}
int solve(int l,int r) {
if (f[l][r]) return f[l][r];
if (l > r) return 0;
if (l == r) return 1;
int pos = -1, mx = -1;
for (int i=l; i<=r; ++i) if (y[i] > mx) pos = i, mx = y[i];
int ans1 = solve(l, pos - 1) + solve(pos + 1, r);
int ans2 = 0;
for (int i=pos-1,j; i>=l; i=j) {
for (j=i-1; j>=l; --j) {
if (Judge(j, i, pos)) {
if (j == l) ans2 += solve(l, i - 1);
continue;
}
if (j + 1 <= i - 1) ans2 += solve(j + 1, i - 1);
break;
}
}
for (int i=pos+1,j; i<=r; i=j) {
for (j=i+1; j<=r; ++j) {
if (Judge(pos, i, j)) {
if (j == r) ans2 += solve(i + 1, r);
continue;
}
if (i + 1 <= j - 1) ans2 += solve(i + 1, j - 1);
break;
}
}
return f[l][r] = max(ans1, ans2 + 1);
}
int maximum_deevs(vector<int> A) {
int n = A.size();
for (int i=1; i<=n; ++i) y[i] = A[i - 1];
return solve(1, n);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Incorrect |
2 ms |
608 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Incorrect |
2 ms |
608 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Incorrect |
2 ms |
608 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Incorrect |
2 ms |
608 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |