デンソークリエイトプログラミングコンテスト2026(AtCoder Beginner Contest 443)
翻译中…
Problem Statement
翻译中…
There is an $N \times N$ grid, and there is one piece placed in each column.
The piece in column $i$ is placed in row $R_i$ from the top.
翻译中…
You can perform the following operation zero or more times:
翻译中…
- Choose a piece that is not in the topmost row and move that piece to the cell directly above it.
翻译中…
Find the minimum number of operations needed to satisfy the following condition for all integers $i$ satisfying $1 \le i \le N-1$:
翻译中…
- Let the piece in column
$i$be in row$x$from the top and the piece in column$i+1$be in row$y$from the top. Then,$|x-y| \le 1$.
翻译中…
You are given $T$ test cases; solve each of them.
翻译中…
Constraints
翻译中…
- All input values are integers.
$1 \le T \le 50000$$2 \le N \le 3 \times 10^5$$1 \le R_i \le N$- For a single input, the sum of
$N$does not exceed$3 \times 10^5$.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
翻译中…
Each test case is given in the following format:
翻译中…
N
R_1 R_2 \dots R_N
翻译中…
Output
翻译中…
Output $T$ lines.
翻译中…
The $i$-th line should contain the answer for the $i$-th test case.
翻译中…
样例
Input #1
5
5
5 2 1 3 4
2
1 1
3
1 3 1
9
9 9 8 2 4 4 3 5 3
20
7 4 6 2 15 5 17 15 1 8 18 1 5 1 12 11 2 7 8 14
Output #1
4
0
1
16
105
This input contains five test cases.
For the first test case, by performing operations as follows, you can satisfy the condition in the problem statement with four operations, which is the minimum.
- Move the piece in the $5$-th column from the left to the cell directly above it. The pieces are in rows $5,2,1,3,3$ from left to right.
- Move the piece in the $1$-st column from the left to the cell directly above it. The pieces are in rows $4,2,1,3,3$ from left to right.
- Move the piece in the $1$-st column from the left to the cell directly above it. The pieces are in rows $3,2,1,3,3$ from left to right.
- Move the piece in the $4$-th column from the left to the cell directly above it. The pieces are in rows $3,2,1,2,3$ from left to right.
For the second test case, the condition is satisfied without performing any operations.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。