Submission #802085

#TimeUsernameProblemLanguageResultExecution timeMemory
802085Sohsoh84Giraffes (JOI22_giraffes)C++17
59 / 100
2389 ms236016 KiB
// Wounds should become scars but I'm cracked instead U+1FAE0 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 300 + 10; int dp[MAXN][MAXN][MAXN], n, A[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> A[i]; for (int len = 1; len <= n; len++) { for (int l = 1; l <= n - len + 1; l++) { for (int tl = 1; tl <= n - len + 1; tl++) { int r = l + len - 1; int tr = tl + len - 1; if (A[l] == tl) dp[len][l][tl] = dp[len - 1][l + 1][tl + 1] + 1; else if (A[r] == tl) dp[len][l][tl] = dp[len - 1][l][tl + 1] + 1; else if (A[l] == tr) dp[len][l][tl] = dp[len - 1][l + 1][tl] + 1; else if (A[r] == tr) dp[len][l][tl] = dp[len - 1][l][tl] + 1; else dp[len][l][tl] = max({ dp[len - 1][l][tl], dp[len - 1][l + 1][tl], dp[len - 1][l][tl + 1], dp[len - 1][l + 1][tl + 1] }); } } } cout << n - dp[n][1][1] << endl; 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...