A. Nearest Minimums

Codeforces
IDCF911A
Time2000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
You are given an array of _n_ integer numbers _a_0, _a_1, ..., _a__n_ - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. ## Input The first line contains positive integer _n_ (2 ≤ _n_ ≤ 105) — size of the given array. The second line contains _n_ integers _a_0, _a_1, ..., _a__n_ - 1 (1 ≤ _a__i_ ≤ 109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. ## Output Print the only number — distance between two nearest minimums in the array. [samples]
给定一个包含 #cf_span[n] 个整数的数组 #cf_span[a0, a1, ..., an - 1]。请找出其中两个最近的最小值之间的距离。题目保证数组中最小值至少出现两次。 第一行包含一个正整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 105]) —— 数组的大小。第二行包含 #cf_span[n] 个整数 #cf_span[a0, a1, ..., an - 1] (#cf_span[1 ≤ ai ≤ 109]) —— 数组的元素。题目保证数组中最小值至少出现两次。 请输出一个数字——数组中两个最近的最小值之间的距离。 ## Input 第一行包含一个正整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 105]) —— 数组的大小。第二行包含 #cf_span[n] 个整数 #cf_span[a0, a1, ..., an - 1] (#cf_span[1 ≤ ai ≤ 109]) —— 数组的元素。题目保证数组中最小值至少出现两次。 ## Output 请输出一个数字——数组中两个最近的最小值之间的距离。 [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the size of the array, with $ 2 \leq n \leq 10^5 $. Let $ A = (a_0, a_1, \dots, a_{n-1}) $ be a sequence of integers with $ 1 \leq a_i \leq 10^9 $. Let $ m = \min(A) $ be the minimum value in $ A $. Let $ I = \{ i \in \{0, 1, \dots, n-1\} \mid a_i = m \} $ be the set of indices where the minimum occurs. **Constraints** 1. $ |I| \geq 2 $ **Objective** Compute the minimum distance between any two distinct indices in $ I $: $$ \min_{\substack{i,j \in I \\ i \ne j}} |i - j| $$
Samples
Input #1
2
3 3
Output #1
1
Input #2
3
5 6 5
Output #2
2
Input #3
9
2 1 3 5 4 1 2 3 1
Output #3
3
API Response (JSON)
{
  "problem": {
    "name": "A. Nearest Minimums",
    "description": {
      "content": "You are given an array of _n_ integer numbers _a_0, _a_1, ..., _a__n_ - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF911A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an array of _n_ integer numbers _a_0, _a_1, ..., _a__n_ - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "给定一个包含 #cf_span[n] 个整数的数组 #cf_span[a0, a1, ..., an - 1]。请找出其中两个最近的最小值之间的距离。题目保证数组中最小值至少出现两次。\n\n第一行包含一个正整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 105]) —— 数组的大小。第二行包含 #cf_span[n] 个整数 #cf_span[a0, a1, ..., an - 1...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the size of the array, with $ 2 \\leq n \\leq 10^5 $.  \nLet $ A = (a_0, a_1, \\dots, a_{n-1}) $ be a sequence of integers with $ 1 \\leq a_i \\leq 10^9 $.  \nLe...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments