All submissions for this problem are available.
A class room in the form of square matrix of size N*N where each cell represent the seat.
In any of the seat invigilator can sit and remaining N*N-1 can be filled by students.The seat at which invigilator sat is marked by '5',seats filled by students are marked by '1' and remaining seats marked by '0'.
You have to calculate the total minimum distance travel by students to give their answer sheet to invigilator.
If invigilator is not present in the class room. Then, total minimum distance is -1
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
First line of each test case contains a single integer N denoted the size of matrix.Each of the next N lines contain N integers denoting the values in the rows of the matrix.
For each test case, output a single line containing the total distance traveled by students.
- 1 ≤ T ≤ 5
- 1 ≤ N ≤ 500
Input: 1 3 1 0 0 5 0 1 0 1 0 Output: 5
Example case 1. invigilator is at (2 1) and students are at (1 1),(2 3) and (3 2).
|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, SCALA, 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, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions