# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850421 | Ahmed57 | Boarding Passes (BOI22_passes) | C++17 | 1 ms | 2396 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |