QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21229. 3D Space Exploration

Statistics

Farmer John's cows have finally blasted off from earth and are now floating around space in their Moocraft. The cows want to reach their fiery kin on Io, a moon of Jupiter, but to do so they first must navigate the dangerous asteroid belt.

Bessie is piloting the craft and must guide it through this treacherous $N \times N \times N$ $1 \le N \le 100$ sector of space. All asteroids in this sector comprise some number of $1 \times 1 \times 1$ blocks of space-rock connected along their faces (two blocks sharing only a vertex or only an edge count as two distinct asteroids).

Please help Bessie by counting the number of distinct asteroids in the field.

Consider a $3 \times 3 \times 3$ space where the first slice of space looks like this, with '$M$' indicating the starting location of the Moocraft (1,1,1) and 'D' is the destination at (3,3,3). In these maps, these markers serve mostly as map orientation rather than providing useful information to solve the problem.

In these diagrams and also in the input, the *'s represent asteroid chunks and each '.' represents a vast void of empty space.

   Close slice    Middle slice     Far Slice     Assembled with overlaps
     +---+            +---+          +---+                  +---+ Far
     |M..|            |..*|          |...|                  |...|
     |.*.|            |.*.|          |.*.|                +---+.|
     |...|            |*..|          |..D|                |..*|D|
     +---+            +---+          +---+              +---+.|-+
                                                        |M..|.|
                                                        |.*.|-+
                                                        |...|
                                                  Close +---+

Visual inspection shows three asteroids, including a long one through the middle of the map. Here's a map with the asteroid pieces labelled:

                                  +---+ Far
                                 /|...|
                                / |.1.|
                               /  |...|
                              /   +---+
                             +---+   /
                            /|..3|  /  
                           / |.1.| /
                          /  |2..|/
                         /   +---+
                        +---+   /
                        |...|  /
                        |.1.| /
                        |...|/
                  Close +---+

Input

  • Line 1: A single integer: $N$
  • Lines $2..N^2+1$: Line $i-1$ contains line $1 + ((k+1)\%N)$ of slice $\operatorname{int}((i+N-1)/N)$: $N$ characters

Output

  • Line 1: A single integer indicating the number of asteroids in the field

Examples

Input 1

3
...
.*.
...
..*
.*.
*..
...
.*.
...

Output 1

3

Problem credits: Andre Kessler, 2010

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.