이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << fixed << setprecision(1) << a << endl
#define debugsl(a) cout << #a << " = " << fixed << setprecision(1) << a << ", "
#define rep(i,a,b) for(int i = (a); i<=(b); i++)
#define repa(i,a,b) for(int i = (a); i>=(b); i--)
#define pll pair<lli,lli>
#define MAX 100000
#define G 7
lli n,k,arr[MAX+2],cont,p_[G+2],vis[G+2],sum[G+2];
long double dp[MAX+2],res,a;
string st;
map<char,lli> mapa;
vector<lli> orden;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> st;
n = st.size();
cont = 1;
rep(i,1,n) {
if (mapa.find((char)st[i-1]) == mapa.end()) mapa[(char)st[i-1]] = cont++;
arr[i] = mapa[st[i-1]];
a = (i-1);
a /= 2;
dp[i] = dp[i-1] + a;
}
res = -1;
rep(mitad,1,n) {
//debug(mitad);
orden.clear();
rep(i,1,G) orden.push_back(i);
do {
cont = 1;
rep(i,0,G-1) {
//debug(orden[i]);
p_[orden[i]] = cont++;
}
long double sub_res = 0;
rep(i,1,G) sum[i] = 0;
rep(i,1,mitad-1) {
rep(j,1,p_[arr[i]]-1) sub_res += sum[j];
sum[p_[arr[i]]]++;
}
//debugsl(sub_res);
rep(i,1,G) sub_res += dp[sum[i]];
//debug(sub_res);
rep(i,1,G) sum[i] = 0;
repa(i,n,mitad) {
rep(j,1,p_[arr[i]]-1) sub_res += sum[j];
sum[p_[arr[i]]]++;
}
//debugsl(sub_res);
rep(i,1,G) sub_res += dp[sum[i]];
//debug(sub_res);
if (res == -1 || sub_res < res) res = sub_res;
} while (next_permutation(orden.begin(), orden.end()));
}
cout << fixed << setprecision(3) << res;
return 0;
}
# | 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... |