Submission #850421

#TimeUsernameProblemLanguageResultExecution timeMemory
850421Ahmed57Boarding Passes (BOI22_passes)C++17
0 / 100
1 ms2396 KiB
#include <bits/stdc++.h> using namespace std; int c = 0; vector<int> arr[15]; short pref[10001][1024],suf[10001][1024]; long double dp[1024]; int sz; long double ge(long double x){ if(x<=1)return 0; return (x*(x-1))/4.0; } int main(){ string s;cin>>s; map<char,int> x; int ind = -1; sz = s.size(); for(auto i:s){ ind++; if(x[i]==0){ x[i] = ++c; arr[c-1].push_back(ind); }else{ arr[x[i]-1].push_back(ind); } } if(c>10){ cout<<"a3"<<endl; return 0; } if(c>1){ for(int mask = 0;mask<(1<<c);mask++){ for(int i = 0;i<sz;i++){ pref[i][mask] = (mask&(1<<(x[s[i]]-1))?1:0); if(i)pref[i][mask]+=pref[i-1][mask]; } for(int i = sz-1;i>=0;i--){ suf[i][mask] =(mask&(1<<(x[s[i]]-1))?1:0); if(i<sz-1)suf[i][mask]+=suf[i+1][mask]; } } } for(int mask = (1<<c)-1;mask>=0;mask--){ if(mask==(1<<c)-1){ dp[mask] = 0; continue; } dp[mask] = 1000000000.0; for(int j = 0;j<c;j++){ if(!(mask&(1<<j))){ long long all = 0 , xd = 0; if(c>1){for(int e = 0;e<arr[j].size();e++){ all+=suf[arr[j][e]][mask]; } } dp[mask] = min(dp[mask],dp[mask^(1<<j)]+all+xd+ge(arr[j].size())); if(c==1)continue; for(int e = 0;e<arr[j].size();e++){ all-=suf[arr[j][e]][mask]; xd+=pref[arr[j][e]][mask]; dp[mask] = min(dp[mask],dp[mask^(1<<j)]+all+xd+ge(e+1)+ge(arr[j].size()-e-1)); } } } } cout<<setprecision(4)<<fixed<<dp[0]<<endl; return 0; }

Compilation message (stderr)

passes.cpp: In function 'int main()':
passes.cpp:51:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             if(c>1){for(int e = 0;e<arr[j].size();e++){
      |                                   ~^~~~~~~~~~~~~~
passes.cpp:57:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for(int e = 0;e<arr[j].size();e++){
      |                           ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...