?题目:https://codeforces.com/contest/1917/problem/B
思想:
代码:
// Problem: B. Erase First or Second Letter
// Contest: Codeforces - Codeforces Round 917 (Div. 2)
// URL: https://codeforces.com/contest/1917/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
int n;
string a;
int b[N][30];
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--){
cin>>n>>a;
a='1'+a;
for(int i=0;i<=n;i++){
for(int j=0;j<=26;j++){
b[i][j]=0;
}
}
for(int i=1;i<=n;i++){
b[i][a[i]-'a']++;
for(int j=0;j<=26;j++){
b[i][j]+=b[i-1][j];
}
}
ll ans=0;
for(int i=n;i>=1;i--){
for(int j=0;j<=26;j++){
ans+=(b[i][j]?1:0);
}
}
cout<<ans<<"\n";
}
return 0;
}