#C5072. Grid Transformation Operations
Grid Transformation Operations
Grid Transformation Operations
You are given an initial grid and a target grid, both of dimensions \(n \times m\). In a single operation, you may choose a row or column and add a constant value to every element in that row or column. Your task is to transform the initial grid into the target grid using the minimum number of such operations.
More formally, you are provided with two matrices \(A = [a_{ij}]\) and \(B = [b_{ij}]\). In one operation, you can add an integer \(d\) to every element of a chosen row \(i\) (i.e., perform \(a_{ij} \leftarrow a_{ij} + d\) for all \(j\)) or to every element of a chosen column \(j\) (i.e., perform \(a_{ij} \leftarrow a_{ij} + d\) for all \(i\)). The goal is to make \(A = B\) with as few operations as possible.
Example:
Input: 2 2 1 2 3 4 2 3 4 5</p>Output: 2 ADD row 0 1 ADD row 1 1
inputFormat
The first line contains two integers, (n) and (m), representing the number of rows and columns of the grid respectively. This is followed by (n) lines each containing (m) space-separated integers that represent the initial grid. The next (n) lines each contain (m) space-separated integers representing the target grid.
outputFormat
The output consists of multiple lines. The first line contains a single integer (k) representing the number of operations. Each of the next (k) lines contains a string describing an operation in the format "ADD row i value" or "ADD column j value", where (i) or (j) is the corresponding row or column index (0-indexed) and "value" is the integer to be added.## sample
2 2
1 2
3 4
2 3
4 5
2
ADD row 0 1
ADD row 1 1
</p>