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>
using namespace std;
typedef long double ld;
typedef long long ll;
string s; int n;
vector <int> pos[26];
int main () {
cin >> s; n = s.length();
for (int i = 0; i < n; i++) {
pos[s[i] - 'A'].push_back(i);
}
int x = 0;
for (int i = 1; i < 26; i++) if (!pos[i].empty()) x = i;
vector <int> dd;
ld mn = 1e18;
for (int i = 0; i <= x; i++) if (!pos[i].empty()) dd.push_back(i);
do {
ld sum = 0;
for (int i = 0; i < (int)dd.size(); i++) {
int m = pos[dd[i]].size();
for (int j = 0; j < m; j++) {
ld cnt = j;
ld cnt2 = m - j - 1;
ld cnt3 = 0, cnt4 = 0;
for (int k = 0; k < i; k++) {
for (auto l : pos[dd[k]]) {
if (l < pos[dd[i]][j]) {
cnt3++;
} else {
cnt4++;
}
}
}
sum += min(cnt * 0.5 + cnt3, cnt2 * 0.5 + cnt4);
}
}
mn = min(mn, sum);
} while (next_permutation(dd.begin(), dd.end()));
cout << fixed << setprecision(6) << mn << '\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... |