atcoder#ABC283F. [ABC283F] Permutation Distance
[ABC283F] Permutation Distance
Score : points
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 (1,2,\ldots,N) is a sequence that is obtained by rearranging (1,2,\ldots,N). In other words, a sequence A of length N is a permutation of (1,2,\ldots,N) if and only if each i\ (1\leq i\leq N) occurs in A 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.
4
3 2 4 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 .
7
1 2 3 4 5 6 7
2 2 2 2 2 2 2
16
12 10 7 14 8 3 11 13 2 5 6 16 4 1 15 9
3 3 3 5 3 4 3 3 4 2 2 4 4 4 4 7