-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6503.cpp
More file actions
54 lines (42 loc) Β· 945 Bytes
/
6503.cpp
File metadata and controls
54 lines (42 loc) Β· 945 Bytes
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
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
void find(int M, string str){
int key[128] = {0,};
int right=-1, left=-1, cnt=0, res=0;
int size = str.size();
while(left <= right){
if(cnt<M || (cnt==M && key[str[right+1]]>0)){
right++;
key[str[right]]++;
if(key[str[right]] == 1)
cnt++;
}
else{
left++;
key[str[left]]--;
if(key[str[left]] == 0)
cnt--;
}
res = max(right - left, res);
if(right == size - 1)
break;
}
cout<<res<<"\n";
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(0);
while(1){
int M;
string str;
cin>>M;
if(M == 0)
break;
getline(cin, str);
getline(cin, str);
find(M, str);
}
return 0;
}