TopcoderArchiveVisit Topcoder
SRM26 Aug 2008
SRM 415

ThreePhotos

Problem statement, definition, constraints, and public examples.

Problem Statement

A cube of size NxNxN was divided into small cubes of size 1x1x1. Then, some of the small cubes were removed, and three photos of the large cube were taken. You are given these three photos in the String[]s A, B and C. Character y of element x of A will be 'Y' if at least one small cube with x-coordinate x and y-coordinate y wasn't removed, or 'N' otherwise. Character z of element x of B will be 'Y' if at least one small cube with x-coordinate x and z-coordinate z wasn't removed, or 'N' otherwise. Character z of element y of C will be 'Y' if at least one small cube with y-coordinate y and z-coordinate z wasn't removed, or 'N' otherwise. Return the minimal number of small cubes which could've been removed to result in those three photos. If there is no way the three photos can be valid, return -1 instead.

Definition

Class:
ThreePhotos
Method:
removeCubes
Parameters:
String[], String[], String[]
Returns:
int
Method signature:
int removeCubes(String[] A, String[] B, String[] C)
(be sure your method is public)

Constraints

  • N will be between 1 and 50, inclusive.
  • A, B and C will each contain exactly N elements.
  • Each element of A, B and C will contain exactly N characters.
  • Each element of A, B and C will contain only 'Y' or 'N' characters.

Examples

  1. {"YY","YY"}
    {"YY","YY"}
    {"YY","YY"}
    Returns: 0
    Remove no cubes.
  2. {"NNN","NNN","NNN"}
    {"NNN","NNN","NNN"}
    {"NNN","NNN","NNN"}
    Returns: 27
    You will have to remove all cubes.
  3. {"NNNNN","NNNNN","NNNNN","YYNNN","NNNNN"}
    {"NNNNN","NNNNN","NNNNN","NNYNY","NNNNN"}
    {"NNYNN","NNNNY","NNNNN","NNNNN","NNNNN"}
    Returns: 123
  4. {"YY","YY"}
    {"YY","YY"}
    {"YN","YN"}
    Returns: -1
Back to all problems