# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
948765 | ifateen | Boarding Passes (BOI22_passes) | C++17 | 2024 ms | 4296 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>
using namespace std;
#define int long long
map<char, int> m;
long double dp[1 << 20];
signed main() {
string s;
cin >> s;
vector<int> v(s.length());
int cnt = 0;
for (int i = 0; i < s.length(); ++i) {
if (m.find(s[i]) != m.end()) v[i] = m[s[i]];
else v[i] = m[s[i]] = cnt++;
}
int G = *max_element(begin(v), end(v)) + 1;
vector<vector<int>> pos(G);
int n = s.length();
for (int i = 0; i < n; ++i) pos[v[i]].push_back(i);
dp[0] = 0;
for (int mask = 1; mask < (1 << G); mask++) {
dp[mask] = 1e18;
for (int i = 0; i < G; i++) {
if (!(mask & (1 << i))) continue;
long double EV = 0;
vector<long double> pref(n);
pref[0] = (v[0] == i ? 0.5 : (mask & (1 << v[0])) ? 1.0 : 0.0);
for (int j = 1; j < n; ++j) {
pref[j] = pref[j - 1];
if (v[j] == i) pref[j] += 0.5;
else if (mask & (1 << v[j])) pref[j] += 1;
}
for (auto &j: pos[i]) {
long double prev = j ? pref[j - 1] : 0, nd = pref[n - 1] - pref[j];
EV += min(prev, nd);
}
dp[mask] = min(dp[mask], EV + dp[mask ^ (1 << i)]);
}
}
cout << fixed << setprecision(8) << dp[(1 << G) - 1];
}
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... |