-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistinct_split.cpp
56 lines (49 loc) · 1.05 KB
/
distinct_split.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr(i,a,b) for (int i =a;i<b;i++)
#define loop(x,n) for (int x = 0;x<n;++x)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
using namespace std;
void precal(){
}
void solve (){
int n;
cin>>n;
string s;
cin>>s;
map <char,int> a, b ;
for (int i=0;i<n;i++){
b[s[i]]++;
}
int maxindex = 0,valmax =0;
for (int i =0;i<n-1;i++){
a[s[i]]++; b[s[i]]--;
if(b[s[i]]==0){
auto iter = b.find(s[i]);
b.erase(iter);
}
if(b.size()+a.size()>valmax){
valmax = a.size()+b.size();
maxindex = i;
}
}
cout<<valmax<<"\n";
}
int main(){
fast_io;
cout<<fixed;
cout<< setprecision(10);
precal();
int t =1;
cin>> t ;
for (int i =1;i<=t;i++){
// cout<< "Case #"<<i<<": ";
solve();
}
return 0;
}