QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#1011#522637#9126. Number of Abbreviationsxielirengrass8cowFailed.2024-10-17 15:51:092024-10-17 15:51:14

詳細信息

Extra Test:

Accepted
time: 0ms
memory: 3848kb

input:

6
abbbaa

output:

15

result:

ok "15"

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#522637#9126. Number of Abbreviationsgrass8cow#AC ✓3ms4464kbC++17286b2024-08-17 09:56:542024-08-17 09:56:54

answer

#include<bits/stdc++.h>
using namespace std;
char c[500100];
int t[26],n;
int main(){
    scanf("%d%s",&n,c+1);
    for(int i=1;i<=n;i++)t[c[i]-'a']++;
    long long ans=0;
    for(int i=0;i<26;i++)ans+=1ll*t[i]*(n-t[i]);
    ans/=2,ans+=n;printf("%lld",ans);
    return 0;
}