You're given the map of a cinema theatre as a boolean matrix: 0 represents a free seat, 1 - occupied. Each Finn who walks in chooses the seat farthest away (Euclidean distance) from the nearest occupied one, or if several such exist - the first among them in row-major order. Output a matrix showing the order seats will eventually be occupied in; that is, replace the 0s with 2, 3, 4, etc
// in
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 1 1 0
// out
2 8 3 9 1
10 5 11 6 12
4 13 14 15 7
16 17 1 1 18
// in
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
// out
5 43 17 44 45 46 18 47 8 48 49 6 50 19 51 2
52 24 53 54 1 55 56 25 57 26 58 59 27 60 28 61
20 62 63 29 64 65 1 66 30 67 68 21 69 9 70 71
72 73 1 74 31 75 76 77 78 1 79 80 32 81 82 11
12 83 84 1 85 86 87 13 88 89 90 14 91 92 33 93
94 34 95 96 97 15 98 99 35 100 36 101 102 1 103 22
104 105 37 106 38 107 39 108 109 16 110 40 111 112 41 113
4 114 115 7 116 23 117 3 118 119 42 120 1 121 122 10
// in
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
// out
2 38 39 26 40 6 41 42 12 43 44 7 45 46 27 47 3
48 49 15 50 28 51 52 29 53 30 54 55 56 16 57 31 58
32 59 60 33 61 62 17 63 64 65 18 66 67 68 34 69 35
70 10 71 72 13 73 74 75 1 76 77 78 11 79 80 14 81
82 83 36 84 85 86 21 87 88 89 22 90 91 37 92 93 94
19 95 96 97 23 98 99 100 24 101 102 103 25 104 105 106 20
107 108 4 109 110 111 8 112 113 114 9 115 116 117 5 118 119
I/O format is flexible within the established code golfing norms for your language. You can assume the input is correct, of size at least 3x3, and doesn't consist entirely of the same boolean value. Write a function or a complete program. The shortest solution per language is considered the winner; no answer will be accepted. Standard loopholes are forbidden.