forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
/
broken.cpp
75 lines (75 loc) · 1.01 KB
/
broken.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 2009-03-26
#include <stdio.h>
#include <string.h>
char infile[20000000];
char outfile[20000000];
char s[1000001];
char *ip,*op;
char c;
int x;
int in()
{
x=0;
for(;;)
{
c=*ip++;
if (c<=32) return x;
x=(x<<1)+(x<<3)+c-'0';
}
}
int d;
void out(int x)
{
if (x<10)
*op++=x+'0';
else
{
d=x/10;
out(d);
d=(d<<1)+(d<<3);
*op++=x-d+'0';
}
}
int get_string(char* t)
{
while ((*t++=*ip++)>=32);
return t-s;
}
int main()
{
fread_unlocked(infile,20000000,1,stdin);
// read(0,infile,20000000);
ip=infile;
op=outfile;
int N,best,cnt,l;
char *begin,*end;
int used[256];
for(;;)
{
if (!(N=in())) break;
getchar();
l=get_string(s);
best=cnt=0;
begin=end=s;
memset(used,0,sizeof(used));
while (*end>=32)
{
if (++used[*end++]==1)
cnt++;
if (cnt>N)
{
while (--used[*begin++]);
cnt=N;
}
if (end-begin>best)
best=end-begin;
if (l-(begin-s)<=best)
break;
}
printf("%d\n",best);
// out(best);
// *op++='\n';
}
// fwrite(outfile,op-outfile,1,stdout);
return 0;
}