## CCC '23 S2 - Symmetric Mountains

View as PDF

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 1G

Author:
Problem type
##### Canadian Computing Competition: 2023 Stage 1, Senior #2

Rebecca is a tour guide and is trying to market the Rocky Mountains for her magazine. She recently took a beautiful picture consisting of mountains where the -th mountain from the left has a height . 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 -th to the -th mountain where . 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 , written as , is the non-negative value of : for example and . The asymmetric value of a crop is the sum of all for . 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).

#### Input Specification

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

The following table shows how the available 15 marks are distributed:

Marks Awarded Bounds on Bounds on Additional Constraints
5 None
5 Height of mountains are in non-decreasing order from left to right.
5 None

#### Output Specification

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

#### Sample Input 1

7
3 1 4 1 5 9 2

#### Output for Sample Input 1

0 2 0 5 2 10 10

#### Explanation of Output for Sample Input 1

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

The height of the mountains in the first crop is . The asymmetric value of this crop is .

The height of the mountains in the second crop is . The asymmetric value of this crop is .

The height of the mountains in the last crop is . The asymmetric value of this crop is .

Hence, the most symmetric crop of length is .

#### Sample Input 2

4
1 3 5 6

#### Output for Sample Input 2

0 1 3 7

#### Explanation of Output for Sample Input 2

This sample satisfies the second subtask. Note that the only crop of length is which has an asymmetric value of .

• commented on Feb. 22, 2024, 3:04 a.m.

• commented on Sept. 28, 2023, 2:00 a.m.

is this doable with python?

• commented on Jan. 21, 2024, 1:48 a.m.

Value's get too large for the programs to compute,I was able to write some python, it got AE, but it got a TLE. I asked ChatGPT to convert it to varius languages, it TLE'd except C# where it Gave points but still gave a TLE. So your program has to be very efficient, and use a language that is fast.

• commented on Sept. 28, 2023, 6:22 a.m.

seems like no one ACed with Python 3, maybe you should try submitting with pypy 3

https://dmoj.ca/problem/ccc23s2/submissions/?status=AC&language=PYPY3

• commented on Feb. 21, 2024, 2:33 p.m.

Nvm s

• commented on Feb. 21, 2024, 2:29 p.m.

legend

• commented on Sept. 29, 2023, 12:54 a.m.

i literally spent 1 hour to figure out ways to make it as fast as possible and work in python but looks like its impossible

• commented on Sept. 28, 2023, 7:12 p.m.

wow thanks dude

• commented on Feb. 18, 2023, 3:38 a.m.

RIP CCC score; still have no idea how to solve subtask 3

• commented on March 14, 2023, 10:32 p.m.

interval dp

• commented on Feb. 18, 2023, 9:05 p.m. edited
• commented on Feb. 23, 2023, 1:28 a.m.

thanks

• commented on Feb. 21, 2023, 7:50 p.m.

Thank you for your hint, your hint is so inspiring that I solved the problem immediately and spontaneously developed an understanding of the c++ language. Thank you.

• commented on Feb. 18, 2023, 9:11 p.m.

??? Is that actually a hint?

• commented on Feb. 18, 2023, 9:19 p.m.

yeah :D

• commented on Feb. 18, 2023, 10:36 p.m. edited

Did you solve all problems on CCC?

Edit: I just realized you r the author