This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n, a[400];
int dp[400][400][400];
int main(){
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = n; i; i--){
for (int j = 1; j <= n; j++) dp[i][i][j] = (a[j] != i);
for (int j = i+1; j <= n; j++) for (int k = 1; k+j-i <= n; k++) dp[i][j][k] = min({dp[i+1][j][k] + (a[k+j-i] != i), dp[i+1][j][k+1] + (a[k] != i)
, dp[i][j-1][k] + (a[k+j-i] != j), dp[i][j-1][k+1] + (a[k] != j)});
}
cout << dp[1][n][1] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |