Submission #1129137

#TimeUsernameProblemLanguageResultExecution timeMemory
1129137adiyerBoarding Passes (BOI22_passes)C++20
55 / 100
506 ms840 KiB
#include <bits/stdc++.h> #define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout); #define adiyer(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define debug cout << "bug"; return; #define bitcount(n) __builtin_popcountll(n) #define all(x) x.begin(), x.end() #define len(s) (int) s.size() #define md ((l + r) >> 1) #define pb push_back #define S second #define F first // #define int long long using namespace std; typedef int ll; typedef long double ld; const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; const int N = 1e5 + 11; const int MAX = 1e6; const int mod = 1e9 + 7; const long long inf = 1e9 + 10; const double eps = 1e-9; ll n, m; ll dp[(1 << 15)], p[N], ok[N]; string s, t; void output(){ cin >> s, n = len(s); for(ll i = 0; i < n; i++) if(t.find(s[i]) == -1) t.pb(s[i]), m++; for(ll msk = 1; msk < (1 << m); msk++){ dp[msk] = inf; for(ll i = 0; i < 15; i++) ok[i] = 0; for(ll i = 0; i < m; i++) if((msk >> i & 1)) ok[t[i] - 'A'] = 1; for(ll i = 0; i < m; i++){ if((msk >> i & 1)){ ll val = 0, cur = 0; for(ll pos = 0; pos < n; pos++){ p[pos] = 0; if(s[pos] == t[i]) p[pos]++; else if(ok[s[pos] - 'A']) p[pos] += 2; if(pos) p[pos] += p[pos - 1]; } for(ll pos = n - 1; pos >= 0; pos--){ if(s[pos] == t[i]) val += min(cur, (pos == 0 ? 0 : p[pos - 1])); if(s[pos] == t[i]) cur++; else if(ok[s[pos] - 'A']) cur += 2; } dp[msk] = min(dp[msk], dp[(msk ^ (1 << i))] + val); } } // cout << msk << ' ' << dp[msk] << '\n'; } if(dp[(1 << m) - 1] % 2 == 0) cout << dp[(1 << m) - 1] / 2; else cout << dp[(1 << m) - 1] / 2 << ".5"; } const bool cases = 0; signed main(){ // file("disrupt"); adiyer(); int tt = 1; if(cases) cin >> tt; for(int i = 1; i <= tt; i++){ output(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...