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>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
signed main(){
fastio
int n;
cin >> n;
int arr[n];
for(auto &x : arr) cin >> x;
int tmp[n];
iota(tmp,tmp+n,1);
int ans = 1e18;
do{
bool ok = true;
for(int i = 0;i < n-1;i++){
if(tmp[i] >= tmp[i+1]+2) ok = false;
}
if(!ok) continue;
int b[n];
for(int i = 0;i < n;i++){
for(int j = 0;j < n;j++){
if(tmp[i]==arr[j]){
b[i] = j;
}
}
}
int cnt = 0;
for(int i = 0;i < n;i++){
for(int j = 0;j < i;j++){
if(b[j] > b[i]){
cnt++;
}
}
}
ans = min(ans,cnt);
}while(next_permutation(tmp,tmp+n));
cout << ans << "\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |