A Puzzle

All submissions for this problem are available.
You are given two $N \times N$ square arrays of integers. Your task is to find out if the second one can be obtained from the first by a *legal sequence* of moves. There are two kinds of moves: **Column Move**: You may pick any column of the array and rotate it up or down by one step. For example, consider the following array: ``` 12 29 40 3 39 25 14 12 14 71 9 61 47 21 53 11 ``` Rotating the fourth column of this array up by one step gives ``` 12 29 40 12 39 25 14 61 14 71 9 11 47 21 53 3 ``` **Row Move**: You may pick any row of the array and rotate it to the right or left by one step. For example, rotating the third row of the array above to the left by one results in ``` 12 29 40 12 39 25 14 61 71 9 11 14 47 21 53 3 ``` Continuing, we could now rotate the first row to the right by one and get ``` 12 12 29 40 39 25 14 61 71 9 11 14 47 21 53 3 ``` A _legal sequence_ of moves consists of a single column move followed by any sequence of row moves. Thus, the sequence of moves carried out above is a legal sequence of moves. Given, two arrays, you task is to find if the second one can be obtained from the first by any legal sequence of moves. ###Input format  The first line of the input contains a single integer $N$ indicating the number of rows (and columns) in the two arrays.  The next $N$ lines (lines $2, \ldots ,N+1$) contain $N$ integers each and describe the first array.  The next $N+1$ lines (lines $N+2, \ldots, 2N + 1$) contain $N$ integers each and describe the second array. ###Output format  If the second array cannot be obtained from the first by any legal sequence of moves, simply output the word "NO".  If the second array can be obtained some legal sequence of moves then the first line of the output must contain the word "YES". Further, the second line must describe a legal sequence of moves that will transform the first array into the second. First output the total number of moves in your legal sequence (this should be an integer between 1 and 100, else you will get Wrong Answer), and then output the sequence as described below.  The column move rotating column i up is denoted by i and the column move rotating column i down is denoted by i. The row move rotating row j to the left is denoted by j and the row move rotating row j right is denoted by j. (Since the first move is a column move and everything else is a row move there is no ambiguity in this notation.)  There may be more than one way to transform the first array to the second and it suffices to output any one legal sequence of moves which does so. ###Constraints  $1 \leq N \leq 8$  $1 \leq$ all array values $\leq 100$ ###Sample Input ``` 4 12 29 40 3 39 25 14 12 14 71 9 61 47 21 53 11 12 12 29 40 39 25 14 61 71 9 11 14 47 21 53 3 ``` ###Sample Output ``` YES 3 4 3 1 ```Author:  admin3 
Date Added:  3112019 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions