Submission #535710

#TimeUsernameProblemLanguageResultExecution timeMemory
535710sam571128Group Photo (JOI21_ho_t3)C++17
5 / 100
5074 ms212 KiB
#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 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...