When walking down the street one day, you suddenly notice a banner that reads:
Japan is turning footsteps into electricity! Using piezoelectric tiles, every step you take generates a small amount of energy. Millions of steps together can power LED lights and displays in busy places like Shibuya Station. A brilliant way to create a sustainable and smart city turning m...
Inspired by this idea, engineers install rows of piezoelectric tiles along a walkway. Each tile records how many footsteps landed on it.
In this problem, you are asked to design three functions
int **create_walkway(int n, const int *len);
void activate_walkway(int n, const int *len, int **tile);
void delete_walkway(int n, int **tile);
The three functions have been declared in function.h, and you are asked to complete the function definitions in function.c.
There are n walkways.
The i-th walkway contains len[i] tiles.
The judge will first generate the initial footstep counts, then store them into your allocated structure, and finally call your processing function.
When the system is activated, each tile generates energy using the footsteps recorded on itself and the tiles immediately next to it on the same walkway.
For each tile j, its new value is the sum of its own original value and the original values of the tiles right next to it (j-1 and j+1), if those neighbors exist
All walkways must be processed independently, and every update must be computed from the original values before any modifications are applied.
Your task is not only to allocate and free memory correctly, but also to simulate this activation process.
int **create_walkway(int n, const int *len);
Allocate memory for n walkways.
The returned result should satisfy:
tile[i] points to a valid writable integer array
tile[i] has exactly len[i] elements
void activate_walkway(int n, const int *len, int **tile);
For each walkway, update every tile according to the activation rule described above.
All new values of one walkway must be computed from the walkway's original values before any tile in that walkway is overwritten.
Note: The return type of Function 2 is void (previously miswritten as long long).
void delete_walkway(int n, int **tile);
Free the memory space of the array that was previously allocated dynamically.
Constraints
The first line contains an integer t, the number of test cases.
For each test case:
The first line contains two integers n and q.
n is the number of walkways.
q is the number of times the activation process will be applied.
The second line contains n integers
len[0], len[1], ..., len[n-1], where len[i] is the number of tiles in the i-th walkway.
The next n lines describe the initial footstep counts of the tiles.
For each i from 0 to n-1, the i-th of these lines contains len[i] integers representing the initial values stored in the tiles of the i-th walkway.
For each test case, after every activation step:
Print n lines.
The i-th line should contain len[i] integers representing the values of the tiles in the i-th walkway after the activation.
Values in the same line should be separated by a single space.