問題一覧 > 通常問題

No.2335 Jump

レベル : / AI推定難易度 : 800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 187
作問者 : SSRS / テスター : platinum 👑 Nachia
お気に入りにしたユーザー ProblemId : 6824 / 自分の提出
問題文最終更新日: 2023-05-30 18:22:04
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 391 (順位表) の他の問題:

Problem Statement

There are $10^{100}$ squares arranged in a row. The $i$-th square from the left ($1 \leq i \leq 10^{100}$) is called square $i$.
There are also $N$ pieces, and the $i$-th piece ($1 \leq i \leq N$) is initially placed on square $A_i$.
Find the minimum number of operations required to reach a state where squares $1,2,\dots,N$ each have $1$ piece on them, by repeating the following operation.

  • Choose $1$ piece, and let $x$ be the square it is on. Perform one of the following $2$ moves.
    • Move the chosen piece to the rightmost square without a piece among squares $1,2, \dots, x-1$. However, this move cannot be performed if all of the squares $1, 2, \dots, x-1$ have pieces on them.
    • Move the chosen piece to the leftmost square without a piece among squares $x+1, x+2, \dots, 10^{100}$. However, this move cannot be performed if all of the squares $x+1, x+2, \dots, 10^{100}$ have pieces on them.
It can be proved that, under the constraints of this problem, it is always possible to reach a state where squares $1,2,\dots,N$ each have $1$ piece on them.

Input

The input is given from standard input in the following format.

$N$
$A_1$ $A_2$ $\cdots$ $A_N$

Output

Print the answer to standard output in $1$ line. Add a newline at the end.

Constraints

The input satisfies the following constraints.

  • $1 \leq N \leq 100\,000$
  • $1 \leq A_1 \lt A_2 \lt \cdots A_N \leq 10^9$
  • All input values are integers.

Sample

Sample 1
Input
3
2 4 5
Output
2

By performing the following steps, you can reach a state where squares $1,2,3$ each have $1$ piece on them in $2$ operations.

  1. Move the piece on square $5$ to square $3$. Squares $2, 3, 4$ now each have $1$ piece on them.
  2. Move the piece on square $4$ to square $1$. Squares $1, 2, 3$ now each have $1$ piece on them.
It is impossible to reach a state where squares $1,2,3$ each have $1$ piece on them in $1$ or fewer operations, so print $2$.
Sample 2
Input
1
1000000000
Output
999999999

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。