Description
A cellular automaton is a collection of cells on a grid of specified shape this evolves through a number of discrete time s Teps according to a set of rules this describe the new state of a cell based on the states of neighboring. The order of the cellular automaton is the number of cells it contains. Cells of the automaton of order n are numbered from 1 to N.
The order of the ' cell is ' the number of different values it may contain. Usually, the values of a cell of order m are considered to is integer numbers from 0 to m−1.
One of the most fundamental properties of a cellular automaton is the type of grid in which it is computed. In this problem we examine the special kind of cellular automaton-circular cellular automaton of order n with cells of O Rder m. We'll denote such kind of cellular automaton as N,m−automaton.
A distance between cells I and J-N,m-automaton is defined as min (|i−j|,n−|i−j|). A denvironment of a cell is the set of cells at a distance not greater than D.
On each d-step values of the all cells are simultaneously replaced by new values. The new value of cell I after d-step are computed as a sum of values of cells belonging to the d-enviroment of the cell i m Odulo m.
The following picture shows 1-step of the 5,3-automaton.
Input
The Inputfile contains several test cases, each of them consists of two, as lines described.
Thefirst line of the input contains four integer numbers n, m, D, and K (1≤n≤500, 1≤m≤1000000, 0≤d < n 2, 1 ≤k≤10000000).
The second line contains n integers numbers from 0 to m−1-initial values of the automaton ' s cells.
Output
For each test case, write to the output and on a line by itself, the values of the N,m-automaton's cells after K d-steps.
Sample Input
5 3 1 1 1 2 2 1 2 5 3 1 1 2 2 1 2
Sample Output
2 2 2 2 1 2 0 0 2 2
the
A cellular automaton contains n squares, the value of each lattice is (0,m), given the distance d, the value of each lattice after each operation becomes the sum of the value of the preceding operation and modulus m of all lattices with its distance not exceeding D, and the value of each lattice after K operation is computed.
train of Thought
We consider the value of each lattice after K operation as the column vector Vk V_{k}, it is not difficult to find that Vk V_k can be obtained by a transformation of vk−1 v_{k-1}, and this transformation is the vk−1 v_{k-1 element and modulus m of the neighboring 2xd+1 2xd+1.
so the whole transformation can be described by matrix multiplication.
Set V0 v_0 as the initial column vector, when d=1 d=1:
a=⎡⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢110⋯ 111110⋯ 101110⋯ ⋯ 01100