Logo
(追記) (追記ここまで)

28313번 - Symmetric Mountains 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB78454366.154%

문제

Rebecca is a tour guide and is trying to market the Rocky Mountains for her magazine. She recently took a beautiful picture consisting of $N$ mountains where the $i$-th mountain from the left has a height $h_i$. She will crop this picture for her magazine, by possibly removing some mountains from the left side of the picture and possibly removing some mountains from the right side of the picture. That is, a crop consists of consecutive mountains starting from the $l$-th to the $r$-th mountain where $l \le r$. To please her magazine readers, Rebecca will try to find the most symmetric crop.

We will measure the asymmetric value of a crop as the sum of the absolute difference for every pair of mountains equidistant from the midpoint of the crop. To help understand that definition, note that the absolute value of a number $v,ドル written as $|v|,ドル is the non-negative value of $v$: for example $|-6| = 6$ and $|14| = 14$. The asymmetric value of a crop is the sum of all $|h_{l+i} - h_{r-i}|$ for 0ドル \le i \le \frac{r-l}{2}$. To put that formula in a different way, we pair up the mountains working from the outside in toward the centre, calculate the absolute difference in height of each of these pairs, and sum them up.

Because Rebecca does not know how wide the picture needs to be, for all possible crop lengths, find the asymmetric value of the most symmetric crop (the crop with the minimum asymmetric value).

입력

The first line consists of an integer $N,ドル representing the number of mountains in the picture. The second line consists of $N$ space-separated integers, where the $i$-th integer from the left represents $h_i$.

출력

Output on one line $N$ space-separated integers, where the $i$-th integer from the left is the asymmetric value of the most symmetric picture of crops of length $i$.

제한

  • 1ドル \le N \le 5,000円$
  • 0ドル \le h_i \le 10^5$

예제 입력 1

7
3 1 4 1 5 9 2

예제 출력 1

0 2 0 5 2 10 10

We will show why the fifth value from the left is 2ドル$. Let us try to compute all the asymmetric values of crops with length 5ドル$.

The height of the mountains in the first crop is $[3, 1, 4, 1, 5]$. The asymmetric value of this crop is $|3 - 5| + |1 - 1| + |4 - 4| = 2$.

The height of the mountains in the second crop is $[1, 4, 1, 5, 9]$. The asymmetric value of this crop is $|1 - 9| + |4 - 5| + |1 - 1| = 9$.

The height of the mountains in the last crop is $[4, 1, 5, 9, 2]$. The asymmetric value of this crop is $|4 - 2| + |1 - 9| + |5 - 5| = 10$.

Hence, the most symmetric crop of length 5ドル$ is 2ドル$.

예제 입력 2

4
1 3 5 6

예제 출력 2

0 1 3 7

This sample satisfies the second subtask. Note that the only crop of length 4ドル$ is $[1, 3, 5, 6]$ which has an asymmetric value of $|1 - 6| + |3 - 5| = 7$.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2023 > CCC 2023 Senior Division 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /