Submission #1122948

#TimeUsernameProblemLanguageResultExecution timeMemory
1122948adiyerBoarding Passes (BOI22_passes)C++20
25 / 100
129 ms436 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 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 long long 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 = 1e2 + 11; const int MAX = 1e6; const int mod = 998244353; const long long inf = 1e9 + 10; const double eps = 1e-9; ll n; double dp[N]; string s, per; void output(){ cin >> s; for(ll i = 0; i < len(s); i++){ if(per.find(s[i]) == -1){ per.pb(s[i]); } } sort(all(per)); double res = inf; do{ double cur = 0; bool was[N] = {}; for(char chr : per){ for(ll i = 0; i < len(s); i++){ if(s[i] != chr) continue; double expf = 0, expb = 0; for(ll j = 0; j < i; j++){ if(was[j]) expf++; if(s[j] == chr) expf += 0.5; } for(ll j = i + 1; j < len(s); j++){ if(was[j]) expb++; if(s[j] == chr) expb += 0.5; } dp[i] = min(expf, expb); cur += dp[i]; } for(ll i = 0; i < len(s); i++) if(s[i] == chr) was[i] = 1; } res = min(res, cur); } while(next_permutation(all(per))); cout << res; } 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...