Back
Close

Dumbbells solver

Statement

 Goal

Dumbbells o-o should be stored in a big box.

Each dumbbell occupies three squares aligned horizontally or vertically: the boxes on both ends contain the weights, the bar is placed in the central square.
The dumbbells can touch but not cross each other.
Each box contains at most one weight, each weight being the end of a single dumbbell.
The weight locations are marked at the bottom of the box. Unfortunately, some of them have been erased.

Find the dumbbells in the grid (the number of dumbbells to put in the box is indicated above).
All problems have a unique solution.

Example

With this grid :

....
o...
..oo


there are two dumbbells easy to find (1 horizontal and 1 vertical) :

...o
o-o|
..oo


Now, we can find a new horizontal dumbbell :

...o
o-o|
o-oo


If there were 3 dumbbells to find, that would be the final solution...

But, if there were 4 dumbbells to find, the final solution would be :

o-oo
o-o|
o-oo
Input
Line 1 : Number n of dumbells.
Line 2 : height h and width w of the grid.
h following lines: the content of the grid of dumbells. (. or o)
Output
h lines : with only ., o, | or -
o
| for a vertical dumbell, o-o for a horizontal dumbell, . for a empty square
o
Constraints
3 <= n <= 15
3 <= h, w <= 8
Example
Input
3
3 4
....
o...
..oo
Output
...o
o-o|
o-oo

Tags
ConditionsLoops2D array

Difficulty
Hard

Test cases
Test 1 (empty not to fill) Test
Input
3 3 4 .... o... ..oo
Output
...o o-o| o-oo

Validator 1 (empty not to fill) Validator
Input
3 4 3 .o. ... o.. o..
Output
oo. ||. oo. o-o

Test 2 (empty to fill) Test
Input
4 3 4 .... o... ..oo
Output
o-oo o-o| o-oo

Validator 2 (empty to fill) Validator
Input
4 4 3 .o. ... o.. o..
Output
ooo ||| ooo o-o

Test 3 Test
Input
14 7 7 .....o. ..o..o. .o..o.. .o....o ......o ....oo. ooo....
Output
o-oo-o. o-oo-oo .o-oo.| .o-o|oo oo..o|o ||o-oo| ooo-o.o

Validator 3 Validator
Input
14 7 7 ..o..oo ..oo.o. .o..... ....oo. ..oo..o oo..... ..ooo..
Output
o-oo-oo o-oo-o| .o-o..o ooo-oo. ||ooo|o oo|||o| ..ooo.o

Test 4 Test
Input
9 5 7 ..o.o.. ooo.o.o ..oo.o. oo.o.oo ..oo.o.
Output
..o-o.. ooo-o.o ||oo-o| oo|o-oo ..oo-o.

Validator 4 Validator
Input
9 7 5 .o.o. .o.o. o.ooo ooo.. ...oo ooo.. .o.o.
Output
.o-o. .o-o. o-ooo ooo|| |||oo ooo.. .o-o.

Test 5 Test
Input
15 8 8 ..oo.o.. .oo....o o..o..oo ..o..... ...o.o.. ..o.o... .o.o.oo. o.oo....
Output
o-oo-o.. .oo..o-o o||oo-oo |oo|...| o..o.ooo ..o-o||. .o-o.oo. o-oo-o..

Validator 5 Validator
Input
15 8 8 .o..o..o o....... oo.oo..o ..o....o .......o ..o...oo o..o..o. .....o..
Output
.o-oo..o o-o.|..| oo-oo..o |.o..o-o o.|o.o-o ..o|o-oo o-ooo-o| ...o-o.o

Solution language

Solution

Stub generator input