Game
Practice
4.6 (10 votes)
Algorithms
Depth first search
Graphs
Medium
Problem
61% Success 1793 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are playing a game in which you have a rectangular grid of n*n cells. Each cell is either empty or has a firework. Empty cells are marked with ".", cells with firework are marked with "*" . Two cells are said to be adjacent if they share a side.

If firework in any cell explodes it destroys itself and the empty cells connected to it. Two cells are connected if there is a path of empty adjacent cells between them.
You have to find the number of cells that will be destroyed if the fireworks are triggered independently.

Input Format:

The first line contains an integer n denoting the dimensions of the grid.
Each of the next n lines contains symbols: "." for empty cells, "*" for cells containing a firework.
Note: All rows have n number of symbols.

Output Format:

Print the sum of the number of cells destroyed if each bomb is triggered independently.

Input Constraints:

\(1 \le n \le 1000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
AlgorithmsDepth First SearchGraphsMedium
Points:30
152 votes
Tags:
ApprovedDepth First SearchGraphsMediumOpen
Points:30
3 votes
Tags:
Breadth-first searchBrute ForceAlgorithmsDepth First SearchGraphsDisjoint Set UnionBitmask