Submission #1040138

#TimeUsernameProblemLanguageResultExecution timeMemory
1040138TAhmed33Cat Exercise (JOI23_ho_t4)C++98
21 / 100
87 ms166520 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e3 + 25; int a[MAXN], n; int dp[MAXN][MAXN]; int mx[MAXN][MAXN]; void solve () { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int l = n; l >= 1; l--) { mx[l][l] = l; dp[l][l] = 0; for (int r = l + 1; r <= n; r++) { if (a[mx[l + 1][r]] > a[mx[l][r - 1]]) { mx[l][r] = mx[l + 1][r]; } else { mx[l][r] = mx[l][r - 1]; } int x = 0; if (mx[l][r] != r) { x = mx[mx[l][r] + 1][r] - mx[l][r]; } int y = 0; if (mx[l][r] != l) { y = mx[l][r] - mx[l][mx[l][r] - 1]; } dp[l][r] = max(x + dp[mx[l][r] + 1][r], y + dp[l][mx[l][r] - 1]); } } cout << dp[1][n] << '\n'; } signed main () { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; //cin >> tc; while (tc--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...