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
using namespace std ;
const int maxn = 12 ;
const int inf = 1e18 ;
int n, ans, v[maxn], go[maxn], test[maxn] ;
int32_t main(){
ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;
cin >> n ;
for(int i = 1 ; i <= n ; i++) cin >> v[i] ;
for(int i = 1 ; i <= n ; i++) test[i] = i ;
ans = inf ;
do{
bool ok = 1 ;
for(int i = 1 ; i < n ; i++){
if(test[i] >= test[i+1] + 2) ok = 0 ;
}
if(!ok) continue ;
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= n ; j++){
if(test[i] == v[j]) go[i] = j ;
}
}
int ct = 0 ;
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j < i ; j++){
if(go[i] < go[j]) ct++ ;
}
}
ans = min(ans, ct) ;
} while(next_permutation(test + 1, test + 1 + 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... |