Submission #666511

#TimeUsernameProblemLanguageResultExecution timeMemory
666511mychecksedadBoarding Passes (BOI22_passes)C++17
5 / 100
405 ms1856 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define setp() cout << setprecision(15) #define all(x) x.begin(), x.end() const int N = 1e5 + 100; int n; string s; double dp[N]; vector<int> v[15], pref, vis; double calc(vector<int> p){ pref.clear(); pref.resize(n); vis.clear(); vis.resize(n); double S = 0; for(int i = 0; i < p.size(); ++i){ long long a = v[p[i]].size(); double best = -1; long long cur = 0; int po = n - 1; for(int j = a - 1; j >= 0; --j){ int pos = v[p[i]][j]; cur += pref[n - 1] - pref[pos]; } best = cur + a*(a-1)/4.0; for(double k = 1; k <= a; k += 1){ int pos = v[p[i]][k - 1]; cur -= pref[n - 1] - pref[pos]; cur += pref[pos]; double k1 = a - k; double val = (k*(k-1) + k1*(k1-1))/4.0 + cur; best = (best == -1 ? val : min(val, best)); } for(int pos: v[p[i]]) vis[pos] = 1; for(int j = 0; j < n; ++j){ if(j == 0) pref[j] = vis[j]; else pref[j] = pref[j - 1] + vis[j]; } S += best; } return S; } void solve(){ cin >> s; n = s.length(); for(int i = 0; i < n; ++i) v[s[i]-'A'].push_back(i); vector<int> p; double ans = 0; for(int i = 0; i < 15; ++i){ double best = -1; int pos = 0; for(int j = 0; j <= i; ++j){ p.insert(p.begin() + j, i); double ans = calc(p); if(best == -1 || best > ans) best = ans, pos = j; p.erase(p.begin() + j); } ans = best; p.insert(p.begin() + pos, i); } cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; setp(); while(T--){ // cout << "Case #" << aa-T << ": "; solve(); } return 0; }

Compilation message (stderr)

passes.cpp: In function 'double calc(std::vector<int>)':
passes.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i = 0; i < p.size(); ++i){
      |                    ~~^~~~~~~~~~
passes.cpp:26:13: warning: unused variable 'po' [-Wunused-variable]
   26 |         int po = n - 1;
      |             ^~
passes.cpp: In function 'int main()':
passes.cpp:97:16: warning: unused variable 'aa' [-Wunused-variable]
   97 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...