Submission #554965

#TimeUsernameProblemLanguageResultExecution timeMemory
554965PietraGroup Photo (JOI21_ho_t3)C++14
5 / 100
4 ms324 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...