#abc283f. F - Permutation Distance
F - Permutation Distance
Score : points
问题描述
给定一个 的排列 。
对于所有 ,求以下值:
- $D _ i=\displaystyle\min_{j\neq i}\left\lparen\left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert\right\rparen$。
什么是排列?排列 是通过重新排列 得到的序列。换句话说,长度为 的序列 是 的排列,当且仅当每个 在 中恰好出现一次。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a permutation of .
Find the following value for all :
- $D _ i=\displaystyle\min_{j\neq i}\left\lparen\left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert\right\rparen$.
What is a permutation? A permutation of is a sequence that is obtained by rearranging . In other words, a sequence of length is a permutation of if and only if each occurs in exactly once.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print in ascending order of , separated by spaces.
Sample Input 1
4
3 2 4 1
Sample Output 1
2 2 3 3
For example, for ,
- if , we have and ;
- if , we have and ;
- if , we have and .
Thus, the value is minimum when , where $\left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert=2$, so .
Sample Input 2
7
1 2 3 4 5 6 7
Sample Output 2
2 2 2 2 2 2 2
Sample Input 3
16
12 10 7 14 8 3 11 13 2 5 6 16 4 1 15 9
Sample Output 3
3 3 3 5 3 4 3 3 4 2 2 4 4 4 4 7
update @ 2024/3/10 11:52:52