Cylon Code
InterviewTime limit2sMemory limit1024 MB
Given an n by m matrix A encoded with a 2x2 matrix C (entries at most 1 in absolute value, C22 nonzero), recover the original matrix B.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
The battlestar Galactica intercepted a message from the Cylons. The message is an integer matrix of size , and it is encoded. After interrogating one of the Cylon sixes, the crew learned how the matrix is encoded. A matrix is used. Each element of is an integer with absolute value at most 1, and . When matrix is encoded, the result is a matrix with the same size as , where If an index falls outside the matrix, that element is taken to be zero. Admiral Adama asks you to decode the Cylon message, since the fate of what remains of humanity depends on it.
Input
The first line contains two integers and (). The next lines each contain integers, which form the encoded matrix . The number in the -th position of the -th line is . The last line contains four integers , , , and , the elements of matrix . All numbers in the input are integers with absolute value at most 1000. For all and , , and .
Output
Print lines with numbers each. These are the elements of the matrix decoded with matrix .