TCCC '24 Apr P4 - Egg Hunt

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
PyPy 3 4.0s
Memory limit: 256M
PyPy 3 512M

Author:
Problem type

Easter has come (past lol)! To celebrate, QuantumFlare's parents are holding their yearly egg hunt as always. In each room of the house, they hide chocolate eggs that may or may not be reachable behind and around impassible obstacles. QuantumFlare. Being a big fan of chocolate, he has decided to efficiently and methodically search each room of the house to find as many eggs as he can. Starting in the top left corner of each room (0,0), he can walk either up, down, left, or right and cannot move through any obstacle. Upon reaching an egg, he will pick it up and add it to his collection. Given the floorplan of the room and the location of every egg and obstacle, help him determine the maximum number of eggs he can collect.

Input Specification

The first line of input will contain two integers, R and C (2 \le R, C \le 1000) representing the number of rows and columns respectively.
The next R lines will be have C characters each, consisting of only ., X and e, representing the map of QuantumFlare's house.

X represents an impassable obstacle.
. represents open ground.
e represents an egg.

Output Specification

A single integer representing the maximum number of eggs QuantumFlare can reach.

Sample Input 1

2 3
.Xe
...

Sample Output 1

1

Explanation for Sample Output 1

There is only 1 egg and it is reachable from QuantumFlare's position.

Sample Input 2

4 4
..Xe
X...
.X..
eXe.

Sample Output 2

2

Explanation for Sample Output 2

One egg is blocked off by obstacles, so QuantumFlare cannot reach it. The other two are still available.


Comments

There are no comments at the moment.