Perspectives II
Minecraft is a game about mining resources and building structures out of cubes. After seeing Saadan's show of wealth, Shashwat wants to one-up him by making a diamond-block structure himself.
He crafts his diamonds into blocks and, unlike Saadan, builds a 3D stucture that may be more than 1 block tall. He then takes three screensbots to share on Discord.
One from the front view (the XY-plane)
One from the side view (the YZ-plane)
One from the above view (the XZ-plane).
From these three perspectives, it is not immediately clear how many diamond blocks Shash's structure actually contains. Peter, astounded, wants to determine the maximum possible number of blocks that could match all screenshots.
For example, if the screenshots look like:
.##
.#.
###
.##
.#.
#.#
#..
###
###
Then Shashwat's structure could contain up to 10 diamond blocks, as shown below:
Input
The first line contains two integers (
), the number of rows and columns visible in each screenshot.
The next lines contains a string
of length
, representing the front view (the XY-plane, rows = Y, columns = X).
The next lines contains a string
of length
, representing the side view (the YZ-plane, rows = Y, columns = Z).
The next lines contains a string
of length
, representing the top view (the XZ-plane, rows = X, columns = Z).
Each character of ,
and
is either:
#
: A diamond block.
: Empty space
Output
Output the maximum number of diamond blocks Shashwat could have used in this structure, given these three perspectives.
Clarifications
- Each perspective will have at least 1 diamond block.
- The perspectives will always correspond to a valid structure.
Example
Input 1
3
.##
.#.
###
.##
.#.
#.#
#..
###
###
Output 1
10
This is the example as given above.
Input 2
2
##
##
##
##
##
##
Output 2
8
Input 3
3
..#
.##
#.#
#..
##.
#.#
#..
#..
###
Output 3
7
Input 4
4
...#
###.
..#.
.#.#
#...
##..
.#..
#.#.
#...
.##.
##..
#...
Output 4
8
Comments