# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535724 | sam571128 | Group Photo (JOI21_ho_t3) | C++17 | 1896 ms | 312 KiB |
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], tmp[n], idk[n];
for(auto &x : arr) cin >> x;
int ans = 1e18;
for(int mask = 0; mask < (1<<n); mask++){
vector<int> v;
for(int i = 0;i < n;i++){
if(mask&(1<<i)) v.push_back(i);
}
for(int i = 0;i < n;i++){
tmp[i] = i+1;
}
for(int i = 1;i < v.size();i += 2){
reverse(tmp+v[i-1],tmp+v[i]+1);
}
for(int i = 0;i < n;i++){
for(int j = 0;j < n;j++){
if(tmp[i]==arr[j]) idk[i] = j;
}
}
int cnt = 0;
for(int i = 0;i < n;i++){
for(int j = 0;j < i;j++){
if(idk[j] > idk[i]){
cnt++;
}
}
}
ans = min(ans,cnt);
}
cout << ans << "\n";
}
Compilation message (stderr)
# | 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... |