#7001. [ICPC 2021 Seoul R] Double Rainbow

    ID: 7001 传统题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P14735单调队列2021ICPC双指针 two-pointer首尔

[ICPC 2021 Seoul R] Double Rainbow

[ICPC 2021 Seoul R] Double Rainbow

题目描述

Let $P$ be a set of $n$ points on the x-axis and each of the points is colored with one of the colors $1, 2, \ldots, k$. For each color $i$ of the $k$ colors, there is at least one point in $P$ which is colored with $i$. For a set $P'$ of consecutive points from $P$, if both $P'$ and $P \setminus P'$ contain at least one point of each color, then we say that $P'$ makes a **double rainbow**. See the below figure as an example. The set $P$ consists of ten points and each of the points is colored by one of the colors $1, 2, 3$, and $4$. The set $P'$ 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 P′P' that makes a double rainbow.

输入格式

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

输出格式

Your program is to write to standard output. Print exactly one line. The line should contain the minimum size of $P'$ that makes a double rainbow. If there is no such $P'$, print $0$.
10 4
1
2
3
1
1
4
2
4
3
3
5
6 3
1
1
2
2
3
3
0

提示

(暂无提示) 标签: P14735|单调队列|2021|ICPC|双指针 two-pointer|首尔

来源

P14735|[ICPC 2021 Seoul R] Double Rainbow