#CT0000146. Cửa sổ thông tin (Information Window)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Cửa sổ thông tin (Information Window)
Information Window
Version: Phuoc Hung OJ Extended
Problem Statement

A system stores a message as a string consisting only of lowercase Latin letters a through z. Each letter denotes one category of information.
The system must choose a nonempty contiguous substring. A substring is valid when it contains at most distinct letters; each letter may appear any number of times.
Choose a valid substring of maximum length. If several substrings have this length, choose the one with the smallest starting position. Character positions are numbered from .
Find the chosen substring's length and starting position.
Input
The first line contains a positive integer .
The second line contains a nonempty string without spaces, using only characters a through z.
Output
Print two integers on one line: the maximum length and the smallest starting position of a substring attaining that length.
Subtasks
- Subtask 1 (30 points): ; ; every character of belongs to
a–z. - Subtask 2 (30 points): ; ; every character of belongs to
a–z. - Subtask 3 (40 points): ; ; every character of belongs to
a–z.
Examples
Example 1
Input
2
abaccc
Output
4 3
Explanation
In abaccc, positions through form accc, of length , with only a and c. Both length- substrings contain a, b, and c, exceeding . The answer is 4 3.
Example 2
Input
1
aabbbcc
Output
3 3
Explanation
For , a valid substring uses only one letter. The maximal same-letter runs are aa (starting at ), bbb (at ), and cc (at ). The longest is bbb, length , starting at .
Example 3
Input
2
abacaba
Output
3 1
Explanation
The length- substrings aba at positions –, aca at –, and aba at – are valid; cab is invalid because it uses three letters. Every length- substring has at least three distinct letters. Hence the maximum length is , with earliest start .
Liên quan
Trong các cuộc thi sau: