CF1208B.Uniqueness

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct.

In other words, at most one time you can choose two integers ll and rr (1≤l≤r≤n1 \leq l \leq r \leq n) and delete integers al,al+1,…,ara_l, a_{l+1}, \ldots, a_r from the array. Remaining elements should be pairwise distinct.

Find the minimum size of the subsegment you need to remove to make all remaining elements distinct.

给你一个数组 a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n}。你最多可以从中移除一个连续子段(即一个子数组)。剩余的元素必须两两互不相同。

换句话说,你最多只能选择一对整数 ll 和 rr(满足 1≤l≤r≤n1 \leq l \leq r \leq n),并从数组中删除元素 al,al+1,…,ara_l, a_{l+1}, \ldots, a_r。剩余的元素必须两两互不相同。

求为使所有剩余元素互不相同,所需删除的子段的最小长度。

输入格式

The first line of the input contains a single integer nn (1≤n≤20001 \le n \le 2000) — the number of elements in the given array.

The next line contains nn spaced integers a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n} (1≤ai≤1091 \le a_{i} \le 10^{9}) — the elements of the array.

输入的第一行包含一个整数 nn(1≤n≤20001 \le n \le 2000)—— 表示给定数组中元素的个数。

接下来一行包含 nn 个用空格分隔的整数 a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n}(1≤ai≤1091 \le a_{i} \le 10^{9})—— 表示数组的元素。

输出格式

Print a single integer — the minimum size of the subsegment you need to remove to make all elements of the array pairwise distinct. If no subsegment needs to be removed, print 00.

输出一个整数——为使数组中所有元素两两互异,你需要删除的最短子段的长度。若无需删除任何子段,则输出 00。

输入输出样例

  • 输入#1

    3
    1 2 3

    输出#1

    0
  • 输入#2

    4
    1 1 2 2

    输出#2

    2
  • 输入#3

    5
    1 4 1 4 9

    输出#3

    2

说明/提示

In the first example all the elements are already distinct, therefore no subsegment needs to be removed.

In the second example you can remove the subsegment from index 22 to 33.

In the third example you can remove the subsegments from index 11 to 22, or from index 22 to 33, or from index 33 to 44.

在第一个例子中,所有元素已经互不相同,因此无需删除任何子段。

在第二个例子中,你可以删除从索引 22 到 33 的子段。

在第三个例子中,你可以删除从索引 11 到 22 的子段,或从索引 22 到 33 的子段,或从索引 33 到 44 的子段。

输入解题思路,AI测评打分。不知道怎么写?

首页