#CT00048. Đoạn phân biệt (Longest Distinct Segment)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đoạn phân biệt (Longest Distinct Segment)
Longest Distinct Segment
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a string consisting of uppercase Latin letters, lowercase Latin letters, and digits. Its positions are numbered from to . A contiguous substring is distinct if no character occurs more than once in it.
Find a longest distinct substring. If several have maximum length, choose the one with the smallest starting position .
Input
One line contains the string , without spaces.
Output
Print three space-separated integers : the maximum length and the endpoints of the chosen substring.
Subtasks
- Subtask 1 (30 points): .
- Subtask 2 (30 points): .
- Subtask 3 (40 points): .
Examples
Example 1
Input
abcaef
Output
5 2 6
Explanation
Positions give abc. At position , a repeats the character at position , so the longest valid substring ending at starts at . Appending e and f gives bcaef at , length . The whole string repeats a, so length is impossible.
Example 2
Input
aaaa
Output
1 1 1
Explanation
Every character is a, so any substring of length at least two contains a repetition. Among the four substrings of length one, choose the earliest: .
Example 3
Input
abcabcbb
Output
3 1 3
Explanation
Valid length-three substrings include abc, bca, and cab. Every length-four substring repeats a character. The earliest maximum-length substring is abc at .
Liên quan
Trong các cuộc thi sau: