#P8781. Alice's Shrub Trimming
Alice's Shrub Trimming
Alice's Shrub Trimming
Alice is tasked with trimming a row of N shrubs arranged from left to right. Initially, all shrubs have a height of 0 cm. Each day, in the morning, every shrub grows by 1 cm. Then in the evening, Alice trims exactly one shrub, resetting its height to 0 cm.
The order in which Alice trims the shrubs is as follows: starting from the leftmost shrub, she trims one shrub per day moving to the right. When she trims the rightmost shrub, she reverses direction and starts trimming to the left. When she reaches the leftmost shrub again, she reverses direction and repeats this pattern indefinitely.
Formally, if the shrubs are numbered from 1 to N from left to right, then the trimming sequence (by shrub index) is:
[ 1, 2, \dots, N-1, N, N-1, \dots, 2, 1, 2, \dots ]
For each shrub, determine the maximum height it attains at any point in time. Note that if a shrub is trimmed, its height resets to 0, and the growth process starts afresh from the next day.
Observation: The maximum height reached by a shrub is equal to the maximum number of consecutive days between two trimming events of that shrub. For shrubs not at the ends (i.e. with index \(1 < i 1\)). Specifically, shrub \(i\) (with \(1 < i < N\)) is trimmed on day \(i\) and on day \(2N-i\) within the cycle. Hence, the gaps between the trimming events are:
[ \text{gap}_1 = (2N - i) - i = 2N - 2i, \quad \text{gap}_2 = (2N-2) - (2N-i) + i = 2i - 2. ]
Thus, the maximum height for shrub \(i\) (where \(1 < i < N\)) is
[ \max(2N-2i,,2i-2). ]
For the endpoints (shrubs 1 and \(N\)), they are trimmed only once per cycle. Their gap is \(2N-2\), so their maximum height is
[ 2N-2. ]
If \(N=1\), the only shrub is trimmed every day, so it never grows beyond 0 cm.
Write a program that, given the integer \(N\), prints the maximum height reached by each shrub from left to right, separated by spaces.
inputFormat
The input consists of a single integer \(N\) (\(1 \le N \le 10^9\)), representing the number of shrubs.
outputFormat
Output \(N\) integers separated by spaces, where the \(i\)th integer is the maximum height (in cm) reached by the \(i\)th shrub.
sample
1
0