Submission #868021

#TimeUsernameProblemLanguageResultExecution timeMemory
868021TAhmed33Boarding Passes (BOI22_passes)C++98
30 / 100
2070 ms1344 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...