#P14735. [ICPC 2021 Seoul R] Double Rainbow

    ID: 16563 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>单调队列2021ICPC双指针 two-pointer首尔

[ICPC 2021 Seoul R] Double Rainbow

题目描述

Let PP be a set of nn points on the x-axis and each of the points is colored with one of the colors 1,2,,k1, 2, \ldots, k. For each color ii of the kk colors, there is at least one point in PP which is colored with ii. For a set PP' of consecutive points from PP, if both PP' and PPP \setminus P' contain at least one point of each color, then we say that PP' makes a double rainbow. See the below figure as an example. The set PP consists of ten points and each of the points is colored by one of the colors 1,2,31, 2, 3, and 44. The set PP' of the five consecutive points contained in the rectangle makes a double rainbow.

:::align{center} :::

Given a set PP of points and the number kk of colors as input, write a program that computes and prints out the minimum size of PP' that makes a double rainbow.

输入格式

Your program is to read from standard input. The input starts with a line containing two integers nn and kk (1kn10,0001 \leq k \leq n \leq 10,000), where nn is the number of the points in PP and kk is the number of the colors. Each of the following nn lines consists of an integer from 11 to kk, inclusively, and the ii-th line corresponds to the color of the ii-th point of PP from the left.

输出格式

Your program is to write to standard output. Print exactly one line. The line should contain the minimum size of PP' that makes a double rainbow. If there is no such PP', print 00.

10 4
1
2
3
1
1
4
2
4
3
3
5
6 3
1
1
2
2
3
3
0