제출 #580146

#제출 시각아이디문제언어결과실행 시간메모리
580146EliasBoarding Passes (BOI22_passes)C++17
25 / 100
25 ms20524 KiB
#include <bits/stdc++.h> #ifndef _DEBUG #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #endif using namespace std; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); string s; cin >> s; int n = s.size(); int g = *max_element(s.begin(), s.end()) - 'A' + 1; vector<int> a(n); vector<vector<int>> pos(g); for (int i = 0; i < n; i++) pos[a[i] = s[i] - 'A'].push_back(i); vector<vector<int>> prefix(1 << g, vector<int>(n)); vector<vector<int>> suffix(1 << g, vector<int>(n)); for (int k = 0; k < 1 << g; k++) { for (int i = 1; i < n; i++) prefix[k][i] = prefix[k][i - 1] + bool(1 << a[i - 1] & k); for (int i = n - 2; i >= 0; i--) suffix[k][i] = suffix[k][i + 1] + bool(1 << a[i + 1] & k); } vector<float> dp(1 << g, 1e20); dp[0] = 0; for (int b = 1; b < 1 << g; b++) { for (int i = 0; i < g; i++) { if (!(b & (1 << i))) continue; float cost = 0; for (int p : pos[i]) { cost += min(prefix[b][p] - 0.5 * prefix[(1 << i)][p], suffix[b][p] - 0.5 * suffix[(1 << i)][p]); } dp[b] = min(dp[b], dp[b ^ (1 << i)] + cost); } } cout << setprecision(15) << dp.back(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...