Accepted
Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
void solve()
{
ll n;cin>>n;
string s;
cin>>s;
map<ll,ll>m;
for(auto x:s )
{
m[x]++;
}
if(n==1)
{
cout<<0<<endl;
return;
}
ll tot=0;ll a;
for(auto x:m)
{
a=x.second;
tot+=(a*(a-1));
}
cout<<tot<<endl;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
ll t;cin>>t;
while(t--)
{
solve();
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1038 Do not touch my string
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2024-03-14 18:44:45
- Judged At
- 2024-03-15 03:59:14
- Judged By
- Score
- 100
- Total Time
- 56ms
- Peak Memory
- 1.43 MiB