Submission #855527

#TimeUsernameProblemLanguageResultExecution timeMemory
855527tvladm2009Giraffes (JOI22_giraffes)C++17
59 / 100
31 ms111188 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 300 + 7; int a[N], pos[N], dp[N][N][N]; int main() { #ifdef ONPC freopen("input.txt", "r", stdin); #else ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif // ONPC int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pos[a[i]] = i; } for (int len = 1; len <= n; len++) { for (int l = 1; l + len - 1 <= n; l++) { for (int t = 1; t + len - 1 <= n; t++) { int r = l + len - 1; int tt = t + len - 1; if (a[l] == t) { dp[len][l][t] = dp[len - 1][l + 1][t + 1] + 1; } else if (a[r] == t) { dp[len][l][t] = dp[len - 1][l][t + 1] + 1; } else if (a[l] == tt) { dp[len][l][t] = dp[len - 1][l + 1][t] + 1; } else if (a[r] == tt) { dp[len][l][t] = dp[len - 1][l][t] + 1; } else { dp[len][l][t] = max({dp[len - 1][l][t], dp[len - 1][l + 1][t], dp[len - 1][l][t + 1], dp[len - 1][l + 1][t + 1]}); } } } } cout << n - dp[n][1][1] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...