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;
void solve(){
int n;cin >> n;
int p[n];for(int i = 0;i < n;i++) {
cin >> p[i];
p[i]--;
}
int dp[n+1][n+1][n+1];
for(int i = 0;i <= n;i++){
for(int j = 0;j <= n;j++) dp[i][n-i][j] = 0;
}
for(int su = n-1;su >= 0;su--){
for(int i = 0;i <= su;i++){
int j = su-i;
int vj = n-j-1;
for(int k = 0;k < n;k++){
dp[i][j][k] = min({
dp[i+1][j][k+1] + (p[k] != i),
dp[i+1][j][k] + (p[k+(n-i-j)-1] != i),
dp[i][j+1][k+1] + (p[k] != vj),
dp[i][j+1][k] + (p[k+(n-i-j)-1] != vj)
});
}
}
}
cout << dp[0][0][0] << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |