Submit | All submissions | Best solutions | Back to list |
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 '.' (full stop) represents a blank field.
- Character '#' represents a fence.
- 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.
Input
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 appearance of Mirko's backyard - positions of the fences, wolves and sheep.
Constraints
3 <= N, M <= 250
Output
In the first and the only line, print the number of sheep and wolves that will survive.
Example
Input:
8 8
.######.
#..k...#
#.####.#
#.#v.#.#
#.#.k#k#
#k.##..#
#.v..v.#
.######. Output: 3 1
Added by: | Erik Lončarek |
Date: | 2012-12-02 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Croatian Regionals 2005 |
hide comments
|
||||||||
2017-10-25 16:55:49
Python/Java solvers, make sure your solution can handle malformed input (blanklines) else NZEC. |
||||||||
2017-07-02 10:44:44
AC in one go !!! solved with dfs.. |
||||||||
2017-03-28 13:27:07
Tutorial level... |
||||||||
2017-03-26 16:55:55
GUYS. EVERYBODY. OUTPUT DOES NOT END WITH NEWLINE. AND IT WILL PASS SOME TEST CASES BEFORE IT GETS WA. It costed me around 10 WAs and 2 weeks of trying to find a bug. removed endl, AC... |
||||||||
2017-03-23 06:18:34
gud one beginners ! |
||||||||
2017-03-03 23:04:29
bfs, NZEC in py3... Found test cases from Croatian Regionals 2005, works fine there... Anyone with the similar problem? http://hsin.hr/zup05/index.html Last edit: 2017-03-03 23:05:00 |
||||||||
2016-12-30 23:49:50
ooo yeah!!!AC in one GO! |
||||||||
2016-10-03 21:06:14
Bfs, AC in two goes :) |
||||||||
2016-09-27 19:07:30
so easy AC in one go |
||||||||
2016-08-15 17:31:56 Sarthak Munshi
perfect problem to start learning about grid walking . |