题目链接
https://atcoder.jp/contests/abc345/tasks/abc345_c
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL C(LL n) {
LL res = n * (n - 1) / 2;
return res;
}
int main() {
string s;
cin >> s;
unordered_map<char, int> mp;
for(int i = 0; i < s.size(); i ++) {
mp[s[i]] ++;
}
bool flag = false;
LL X = C(s.size());
for(auto& [u, v] : mp) {
X -= C(v);
if(v > 1) flag = true;
}
if(flag == true) cout << X + 1 << '\n';
else cout << X << '\n';
return 0;
}