Untitled
unknown
c_cpp
a year ago
784 B
4
Indexable
Never
#include<bits/stdc++.h> #define MAX_CHAR 26 using namespace std; string S; int k; int PoWMod(int n){ int tong = 1; for(int i = 1; i <= 2; i++){ tong *= n; } return tong; } void Min_String(){ cin>>k; cin.ignore(); getline(cin,S); int F[MAX_CHAR]; memset(F, 0, sizeof(F)); for(int i=0;i < (int)S.size();i++){ F[S[i]-'a']++; } priority_queue<int> Q; for(int i=0;i<MAX_CHAR;i++){ Q.push(F[i]); } while(k--){ int t=Q.top(); Q.pop(); t--; Q.push(t); } long long tong = 0; while(!Q.empty()){ int s=Q.top(); tong += (1ll)*PoWMod(s); Q.pop(); } cout << tong; } int main(){ Min_String(); }