#P5940. Chessboard Jumping Transformation
Chessboard Jumping Transformation
Chessboard Jumping Transformation
The chessboard is divided into many regions, and each region can hold multiple chess pieces. A special labeling is applied: one region is labeled \(0\), the regions to its left are labeled \(-1, -2, -3, \dots\) and the regions to its right are labeled \(1, 2, 3, \dots\).
Whenever a region \(P\) contains at least one piece, that piece can jump in one of two ways:
- Left jump: Remove one piece from region \(P\), and add one piece each to regions \(P-1\) and \(P-2\). (This move increases the total number of pieces by 1.)
- Right jump: Provided that both region \(P\) and its immediate right neighbor \(P+1\) each have at least one piece, remove one piece from each of these two regions and add one piece to region \(P+2\). (This move decreases the total number of pieces by 1.)
Starting from a given initial configuration, after a sequence of jumps (in any valid order) one can always reach a target configuration in which for any two adjacent regions the total number of pieces does not exceed \(1\). In other words, if \(a_i\) is the number of pieces in region \(i\), then for every adjacent pair \(i\) and \(i+1\) we have:
[ a_i + a_{i+1} \le 1. ]
Your task is to transform a given initial configuration into the final target configuration by repeatedly applying valid jumps.
Note: The final configuration is unique regardless of the order in which the moves are applied.
inputFormat
The input begins with an odd integer \(n\) on the first line, representing the number of consecutive regions in the initial configuration. The regions are given in order. The middle region (the \((n \div 2) + 1\)-th number where indices are 0-based) is labeled \(0\). Regions to its left are labeled with negative integers and to its right with positive integers.
The second line contains \(n\) space-separated nonnegative integers. The \(i\)-th number (1-indexed) represents the number of pieces in that region.
For example: If the input is 5
and then 0 1 1 0 0
, the regions are labeled as follows: region \(-2\)=0, region \(-1\)=1, region \(0\)=1, region \(1\)=0, and region \(2\)=0.
outputFormat
Output a single line representing the final configuration. Let \(L\) be the smallest index that has a nonzero number of pieces and \(R\) be the largest such index. For each region from \(L\) to \(R\) (inclusive), output the number of pieces in that region consecutively without any spaces.
For example: If the final configuration has a piece in region \(-2\) and a piece in region \(1\) (with zeros in between), then the output should be 1001
(the first digit corresponds to region \(-2\), next to \(-1\), etc.).
sample
1
1
1