# [Community Puzzle] Flood fill Example

https://www.codingame.com/training/medium/flood-fill-example

13 posts were merged into an existing topic: [Community Puzzle] Flood Fill Simple Example

Hi everyone,

Iâm succeeding everything but the 4th validator. Any idea what it could be?

Cheers.

I had a same problem with you. It may be you need to think that the tower can have same I.D. as puzzle said. That means you should distinguish the towers even if I.D is same. I misread description and spend a hour to figure it out.

3 Likes

OooohâŚ sneaky rule, good point, thanks a lot!

1 Like

But Test 4 Also has Different towers with same ID

Yes, That is same ID, but not in same distance

I find the rules quite unclear on two points:

1. Is is really not clear that apparition of + sign doesnât stop the flood fills (in other word, +'s propagate as well)
2. It is really not clear that meetings between towers with the same ID result in a + sign
3 Likes

Your 1. is very clear, thereâs no mention of floodfill at all except in the tag. Itâs all about âclosest towerâ, so it can be defined for any spot.

I agree with your 2., itâs not very clear and you discover it only with test 5. Iâll try to edit to make it clearer.

2 Likes

I donât understand why at time = 2 there is not a + in (2,1) , since b and b arrive at the same time. (same (4,1) and (2,3)). Thanks

Which case?

In example :

``````Consider the following grid:

...#.
A#...
#..B.
.....

At time = 1, they will reachâŚ

A..#.
A#.B.
#.BBB
...B.

At time = 2, they will reachâŚ

AA.#.
A#BBB
#BBBB
..BBB
``````

if you are :
.B
BB

why
BB
BB

and not
+B
BB
?

1 Like

Because B is only one tower; the purpose of the flood fill here is to mark the coverage of that tower, it is not to grow more towers. Compare with test case 5, where there are two towers A.

Sorry but I do not understand. I saw case nÂ°5, but I donât see the difference.

The rule stated by the statement is that âIf 2 towers can reach a spot at the exact same time, mark that spot â+â, even if both towers share the same I.DâŚâ

Tower B is just one tower, so it does not fall within the scope of the above rule.

But in test case 5, there are two towers both named A. âTwo towers sharing the same I.D. of Aâ fall within the scope of the above rule.

In short, you count the number of letters in the input data (the initial state), and that is the number of towers you have to deal with.

1 Like

And if you are still confused, remember that you are converting a map of towers into a map of tower coverage. The flood fill does not indicate additional towers (there are NOT tens of towers of the same I.D. on the map!); the I.D.s on the map you have to output merely show which tower covers each spot.

ok, thanks, iâm starting to understand the problem. I canât see how to solve it yet but Iâll think about it and come back if I canât.

1 Like

can someone explain why thereâs `+` in (6,4) in test case 2? the `5` tower can reach (6,4) at time = 6, the `2` tower can reach (6,4) at time = 5

``````#....##..#.#
#.#..#..5..#
...#........
......##....
......#..#..
1...........
............
.#.2#.......
...#..3.#.#.
....#.....#.
....#.....#.
...4...#....
``````

Not sure which cell youâre referring to as (6, 4). Would you please edit your message and mark that cell using another character?