#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
#include "mountains.h"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 2001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 35;
int dp[NMAX][NMAX];
class ConvexHull{
pii stiva[NMAX];
int vf;
bool OK(pii a, pii b, pii c){
return ((a.first * (b.second - c.second) + b.first * (c.second - a.second) + c.first * (a.second - b.second)) <= 0);
}
public:
int size(){
return vf;
}
int last(){
return stiva[vf].first;
}
int lastbutone(){
return stiva[vf - 1].first;
}
void push(pii x){
while(vf > 1 && OK(stiva[vf], stiva[vf - 1], x)){
vf--;
}
stiva[++vf] = x;
}
}hull;
int maximum_deevs(vector<int> y) {
int i, j;
int n = y.size();
for(i = n; i >= 1; i--) {
for(j = i; j <= n; j++) {
hull.push({j, y[j - 1]});
int ultim = hull.last();
if(i == j)
dp[i][j] = 1;
dp[i][j] = max(dp[i][j], dp[i][ultim - 1] + dp[ultim + 1][j]);
if(hull.size() > 1) {
int penultim = hull.lastbutone();
dp[i][j] = max(dp[i][j], dp[i][penultim - 1] + dp[penultim + 1][j]);
}
}
}
return dp[1][n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |