Submission #580168

#TimeUsernameProblemLanguageResultExecution timeMemory
580168EliasBoarding Passes (BOI22_passes)C++17
60 / 100
498 ms1048576 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; #define int int64_t 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<int> 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; int cost = 0; for (int p : pos[i]) { cost += min(2 * prefix[b][p] - prefix[(1 << i)][p], 2 * suffix[b][p] - suffix[(1 << i)][p]); } dp[b] = min(dp[b], dp[b ^ (1 << i)] + cost); } } cout << setprecision(15) << dp.back() * 0.5; }

Compilation message (stderr)

passes.cpp: In function 'int main()':
passes.cpp:41:28: warning: overflow in conversion from 'double' to 'std::vector<long int>::value_type' {aka 'long int'} changes value from '1.0e+20' to '9223372036854775807' [-Woverflow]
   41 |     vector<int> dp(1 << g, 1e20);
      |                            ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...