#include "mountains.h"
#include <vector>
#include <algorithm>
#include <cstdio>
std::vector<int> ys;
int memo[2001][2001];
int solve(int begin,int end){
if(begin==end) return 0;
if(end-begin==1) return 1;
if(memo[begin][end]!=-1) return memo[begin][end];
std::vector<int> sub;
for(int it=begin+1;it<end;it++){
sub.push_back(it);
}
std::stable_sort(sub.begin(),sub.end(),[begin](int a,int b){return (a-begin)*(ys[b]-ys[begin])>(b-begin)*(ys[a]-ys[begin]);});
std::reverse(sub.begin(),sub.end());
int ans=1;
for(int it:sub){
ans=solve(begin,it)+solve(it+1,end);
break;
}
return memo[begin][end]=std::max(ans,solve(begin+1,end));
}
int maximum_deevs(std::vector<int> y) {
for(int i=0;i<=y.size();i++){
for(int j=0;j<=y.size();j++){
memo[i][j]=-1;
}
}
ys=y;
return solve(0,y.size());
}
Compilation message
mountains.cpp: In function 'int maximum_deevs(std::vector<int>)':
mountains.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<=y.size();i++){
~^~~~~~~~~~
mountains.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<=y.size();j++){
~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |