Submission #989288

#TimeUsernameProblemLanguageResultExecution timeMemory
989288AdamGSMountains (IOI17_mountains)C++17
100 / 100
75 ms71360 KiB
#include "mountains.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=2e3+7; pair<int,int>ma1[LIM][LIM], ma2[LIM][LIM]; ll T[LIM]; int dp[LIM][LIM], odw[LIM][LIM], n; ll ilo(int a, int b, int c) { pair<ll,ll>x={b-a, T[b]-T[a]}, y={c-a, T[c]-T[a]}; return x.st*y.nd-x.nd*y.st; } int solve(int l, int r) { if(l>r) return 0; if(odw[l][r]) return dp[l][r]; odw[l][r]=1; if(ma1[l][r].nd!=-ma2[l][r].nd) { dp[l][r]=max(solve(l, -ma2[l][r].nd-1)+solve(-ma2[l][r].nd+1, r), solve(l, ma1[l][r].nd-1)+solve(ma1[l][r].nd+1, r)); return dp[l][r]; } int x=ma1[l][r].nd; dp[l][r]=solve(l, x-1)+solve(x+1, r); int sum=1, lst=x+1; for(int i=x+2; i<=r; ++i) { if(ilo(x, lst, i)>=0) { sum+=solve(lst+1, i-1); lst=i; } } sum+=solve(lst+1, r); lst=x-1; for(int i=x-2; i>=l; --i) { if(ilo(x, lst, i)<=0) { sum+=solve(i+1, lst-1); lst=i; } } sum+=solve(l, lst-1); dp[l][r]=max(dp[l][r], sum); return dp[l][r]; } int maximum_deevs(vector<int>_y) { n=_y.size(); rep(i, n) T[i]=_y[i]; rep(i, n) { ma1[i][i]={T[i], i}; ma2[i][i]={T[i], -i}; for(int j=i+1; j<n; ++j) { ma1[i][j]=max(ma1[i][j-1], {T[j], j}); ma2[i][j]=max(ma2[i][j-1], {T[j], -j}); } } return solve(0, n-1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...