#P7544. [COCI 2019/2020 #4] Nivelle

[COCI 2019/2020 #4] Nivelle

Description

Bojan saw nn cute edible plush toys on a store shelf, numbered from 11 to nn. Each plush toy has one of 2626 different colors. Each color is represented by a lowercase English letter a...za...z.

For any set of toys, we define its “colorfulness” as the number of distinct colors in the set divided by the total number of toys in the set.

Bojan wants to eat these toys, but he does not like having too many colors. Please help Bojan find a contiguous subsequence of toys whose colorfulness is as small as possible.

Input Format

The first line contains a positive integer nn, the number of toys.
The second line contains a string SS of length nn, where the ii-th character represents the color of the ii-th toy on the shelf.

Output Format

Output a single line containing two integers l,rl, r, the left and right endpoints of the required contiguous subsequence.
If there are multiple contiguous subsequences with the same (minimal) colorfulness, output any one of them.

4
honi
1 4
7
nivelle
4 7
6
ananas
1 5

Hint

Constraints and Notes

This problem uses bundled subtasks. There are 5 subtasks in total.

  • Subtask 1 (7 points): 1n1001 \leq n \leq 100;
  • Subtask 2 (17 points): 1n2×1031 \leq n \leq 2 \times 10^3;
  • Subtask 3 (13 points): the string SS contains only two characters a,ba, b (you can think of it as there are only two colors in all toys).
  • Subtask 4 (25 points): the string SS contains only five characters a,b,c,d,ea, b, c, d, e (you can think of it as there are only five colors in all toys).
  • Subtask 5 (48 points): no special restrictions.

For all testdata, it is guaranteed that 1n1051 \leq n \leq 10^5 and 1lrn1 \leq l \leq r \leq n.

[Hints and Help]

Translated from COCI 2019/2020 CONTEST #4 T5 Nivelle.

In COCI, this problem is worth 110110 points.

Translated by ChatGPT 5