Submission #1188345

#TimeUsernameProblemLanguageResultExecution timeMemory
1188345LucasLeGiraffes (JOI22_giraffes)C++20
59 / 100
35 ms55624 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 <= 300 && 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...