#CT00042. Đoạn nén tốt nhất (Best Compressible Segment)
Đoạn nén tốt nhất (Best Compressible Segment)
Best Compressible Segment
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a string of uppercase Latin letters. Positions are numbered from to .
For any contiguous substring , split it into maximal consecutive runs of equal characters. The number of runs is also the number of letter-count pairs in its run-length encoding.
A substring is called good for compression if it contains at most runs.
Choose a good substring with maximum length. If several substrings have the same maximum length, choose the one with the smallest starting position .
Find the maximum length and the endpoints of the chosen substring.
Input
- Line 1 contains integers and .
- Line 2 contains with exactly characters, all from
A..Z.
Output
Print three integers: the maximum length, , and , in this order.
Subtasks
- Subtask 1 (30 points): .
- Subtask 2 (30 points): .
- Subtask 3 (40 points): no additional restriction.
- In every subtask: .
Examples
Input
13 2
AAABBCCCCDDAA
Output
6 4 9
Explanation
The runs are AAA, BB, CCCC, DD, and AA.
Two longest substrings with at most runs are BBCCCC and CCCCDD. Both have length . The first one starts earlier, so and . Therefore the output is 6 4 9.
Liên quan
Trong các cuộc thi sau:
Phước Hưng - Kỳ Thi HSG Lớp 9 (Chuyên đề Xử Lý Chuỗi) - Đề Số 3