Washing Windows

All submissions for this problem are available.
### Read problem statements in [Bengali](http://www.codechef.com/download/translated/LTIME78/bengali/APARTS.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/LTIME78/mandarin/APARTS.pdf), [Russian](http://www.codechef.com/download/translated/LTIME78/russian/APARTS.pdf), and [Vietnamese](http://www.codechef.com/download/translated/LTIME78/vietnamese/APARTS.pdf) as well. There is a building with $N$ floors (numbered $1$ through $N$ from bottom to top); on each floor, there are $M$ windows (numbered $1$ through $M$ from left to right). Let's denote the $j$th window on the $i$th floor by $(i, j)$. All windows in the building need to be cleaned one by one in a specific order. You are given this order as a matrix $A$ with $N$ rows and $M$ columns; for each valid $i$ and $j$, the window $(i, j)$ must be cleaned on the $A_{Ni+1,j}$th turn. Whenever we clean a window $(i, j)$, it becomes clean, but the dirty water used for cleaning it flows down to windows $(i1, j1)$, $(i1, j)$ and $(i1, j+1)$ (more precisely, to all of these windows which exist), so these windows become dirty again. Then, the water flows further down, so the same applies for other windows below: whenever a window $(i, j)$ becomes dirty, windows $(i1, j1)$, $(i1, j)$ and $(i1, j+1)$ become dirty as well. For example, cleaning a window $(5, 3)$ will make the window $(3, 2)$ dirty. The next window is cleaned only after water flows down completely. Note that each window is cleaned only once and there may be dirty windows at the end. For each window, determine whether it will be clean after the cleaning process ends. ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains two spaceseparated integers $N$ and $M$.  $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$th of these lines contains $M$ spaceseparated integers $A_{i, 1}, A_{i, 2}, \ldots, A_{i, M}$. ### Output For each test case, print $N$ lines; each of them should contain a string with length $M$. For each valid $i$ and $j$, the $j$th character on the $i$th line should be '1' if the window $(Ni+1, j)$ is clean or '0' if it is dirty. ### Constraints  $1 \le T \le 1,000$  $1 \le N, M \le 10^3$  $1 \le A_{i, j} \le N \cdot M$ for each valid $i, j$  the elements of the matrix $A$ are pairwise distinct  the sum of $N \cdot M$ over all test cases does not exceed $10^6$ ### Subtasks **Subtask #1 (50 points):**  $N, M \le 25$  the sum of $N \cdot M$ over all test cases does not exceed $625$ **Subtask #2 (50 points):** original constraints ### Example Input ``` 1 3 4 1 3 7 10 9 2 4 11 8 12 5 6 ``` ### Example Output ``` 1111 1001 0100 ```Author:  kingofnumbers 
Editorial  https://discuss.codechef.com/problems/APARTS 
Tags  deadwing97, dp, easy, kingofnumbers, ltime78 
Date Added:  29112019 
Time Limit:  1 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
HELP
If you are still having problems, see a sample solution here. 