F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Substring

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1702    Accepted Submission(s): 681


Problem Description
You are given a string $S[1..N]$ containing only lowercase letters. Now you need to find the longest substring $S[l..r]$ such that every letter (`a` to `z`) appears no more than $K$ times in the substring. You just need to output the length ($r-l+1$) of the longest substring.
 

Input
There are multiple test cases.

Each test case contains one integer $K$ ($1\leq K \leq N$) and one string $S$ in one line.

It's guaranteed that the sum of lengths of the input strings is no more than $4 \times 10^5$.
 

Output
For each test case, print one integer in one line, denoting the length of the longest substring.
 

Sample Input
1 abcabcabc 2 abcabcabc 2 aaabbbccc
 

Sample Output
3 6 4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 04:56:23, Gzip enabled