Rat Maze With Multiple Jumps
Medium Accuracy: 18.26% Submissions: 3798 Points: 4

A Maze is given as N*N binary matrix of blocks where source block is the upper left most block i.e., maze and destination block is lower rightmost block i.e., maze[N-1][N-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If multiple solutions exist, the shortest earliest hop will be accepted. For the same hop distance at any point, forward will be preferred over downward.
In the maze matrix, 0 means the block is the dead end and non-zero number means the block can be used in the path from source to destination. The non-zero value of mat[i][j] indicates number of maximum jumps rat can make from cell mat[i][j].
In this variation, Rat is allowed to jump multiple steps at a time instead of 1.

Input:
The first line of input contains an integer T denoting the number of test cases. For each test case, the first line contains an integer n denoting the size of the square matrix followed by  N*N space-separated values of the matrix m where 0's represents blocked paths and any number represents valid paths.

Output:
For each test case, the output is a matrix containing 1 for the path taken and 0 for not chosen path. If no path exists print -1.

Constraints:
1 <= T <= 50
2 <= n <= 10
0 <= m[i][j] <= 5

Example:
Input

2

2 1 0 0
3 0 0 1
0 1 0 1
0 0 0 1
4
2 1 0 0
2 0 0 1
0 1 0 1
0 0 0 1

Output:
1 0 0 0
1 0 0 1
0 0 0 1
0 0 0 1
-1

Explanation:
Testcase 1:
Rat started with m and can jump up to 2 steps right/down. First check m as it is 1, next check m, this won't lead to the solution. Then check m, as this is 3(non-zero), so we can make 3 jumps to reach m. From m we can move downwards taking 1 jump each time to reach destination at m.

Testcase 2: As no path exists, so -1.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8769722,"math_prob":0.9803513,"size":1703,"snap":"2020-34-2020-40","text_gpt3_token_len":442,"char_repetition_ratio":0.10417893,"word_repetition_ratio":0.0065789474,"special_character_ratio":0.27657077,"punctuation_ratio":0.11023622,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98538595,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-28T00:15:32Z\",\"WARC-Record-ID\":\"<urn:uuid:6009f8cb-9b32-4b41-b70f-3a98d97e3a50>\",\"Content-Length\":\"88554\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3b6ecc27-b79d-467e-9b5e-fceb926b08cf>\",\"WARC-Concurrent-To\":\"<urn:uuid:86658153-23d5-4e2a-be78-af16a2844460>\",\"WARC-IP-Address\":\"23.45.180.211\",\"WARC-Target-URI\":\"https://practice.geeksforgeeks.org/problems/rat-maze-with-multiple-jumps/0\",\"WARC-Payload-Digest\":\"sha1:PGIGAMREI7GSIP6XZBFVUQIZP2YK6QBW\",\"WARC-Block-Digest\":\"sha1:2WGDZL2LDINVOLG7KNA5P3543SODOPXB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600401582033.88_warc_CC-MAIN-20200927215009-20200928005009-00638.warc.gz\"}"}