KOZE - Sheep
Mirko has a herd of sheep, surrounded by fences backyard. While he was asleep, wolves have sneaked into the fenced area and attacked the sheep.
Backyard is of a rectangular shape, and consists of fields arranged in rows and columns.
Character '.' (fullstop) represents a blank field.
Character '#' represents a fance.
Character 'k' represents a sheep.
Character 'v' represents a wolf.
Two fields belong to the same sector if we can move from the field A to the field B without going over the fence, by making only horizontal and vertical steps (we cannot move diagonally).
If we can escape from field A from the backyard, that field does not belong to any sector.
Luckily, Mirko taught his sheep Kung-Fu skills, and they can defend themselves against wolves only if they outnumber the wolves in that sector. When there are more sheep in the sector than wolves, all wolves die without sheep casualties. Otherwise all sheep perish and wolves are unharmed. If a field doesn't belong in any sector, sheep will flee and wolfs will be left without a prey, so every animal survives.
Write a program that will determine how many sheep and wolves will survive this bloody night.
Integers N and M, number of rows and columns which represent Mirko's backyard.
In every of the N lines, there are M characters representing the appearence of Mirko's backyard - positions of the fences, wolves and sheep.
3 <= N, M <= 250
In the first and the only line, print the number of sheep and wolves that will survive.
.######. Output: 3 1
Took 1 Hour for AC
In case of equal count, all sheep perish and wolves are unharmed.. unfair;)
AC in one GO !! DFS + Connected components
easy dfs :)
Ac in one go use directional bfs and don't compare for boundary sheef and wolf ...hopefully you will get AC
for those who still getting NZECs with py3, you should try to ignore leading blank lines before reading n and m.
Accepted in first go!
Python/Java solvers, make sure your solution can handle malformed input (blanklines) else NZEC.
AC in one gooooooooooooooo!!!!!!!!!!!