Connection Status:
Competition Arena > ThreeLLogo
SRM 616 · 2013-12-22 · by tourist · Dynamic Programming
Class Name: ThreeLLogo
Return Type: long
Method Name: countWays
Arg Types: (vector<string>)
Problem Statement

Problem Statement

Please note that this problem has a non-standard time limit: 3 seconds.

A yet unknown "LLL Company" wants to design a logo. After a long discussion, company designers decided that the logo should consist of three letters L drawn in some way.

To start with something, designers drew N rows of M points each, one under another, so that these points form a rectangular grid. They also painted each point either white or black. Here is an example of what they could get for N = 4 and M = 5:



Designers agreed to draw each letter L as a union of a horizontal and a vertical line segment intersecting at their left and bottom ends, respectively. The segments must have positive lengths, and their endpoints must be white grid points. All grid points that lie on the segments must be white as well. For example, here are two valid placements of a letter:

 

Note that neither the letters nor the grid can be rotated.

The final requirement is that the three letters should be disjoint. That is, no white point should lie on two segments belonging to different letters.

You are given the grid with N rows and M columns, encoded as a String[] grid with N elements, each containing M characters. Each character is either '.' or '#', meaning that the corresponding point is either white or black, respectively.

Return the number of different possible logos with three L's drawn on them according to the requirements. Two logos are considered different if there is a pair of points that is connected by a line segment in exactly one of the logos.

Constraints

  • grid will contain between 2 and 30 elements, inclusive.
  • All elements of grid will contain the same number of characters.
  • Each element of grid will contain between 2 and 30 characters, inclusive.
  • Each character of grid will be either '.' or '#'.
Examples
0)
{"......",
 "......"}
Returns: 1
1)
{".##..",
 ".....",
 ".#.#.",
 "#...#"}
Returns: 3

This is the example from the problem statement. The three possible logos look as follows:

2)
{"....",
 "#...",
 "....",
 "..#."}
Returns: 4
3)
{"..",
 ".."}
Returns: 0

Too small for a logo.

4)
{".#.#",
 "....",
 ".#.#",
 "...."}
Returns: 12
5)
{"######.#######",
 "######.#######",
 "#.####.#######",
 "#.####.#######",
 "#.####........",
 "#.############",
 "#.############",
 "#.############",
 "#.#####.######",
 "#.#####.######",
 "#.#####.######",
 "#....##.######",
 "#######.######",
 "#######.######",
 "#######.######",
 "#######.######",
 "#######.######",
 "#######.######",
 "#######......#",
 "##############"}
Returns: 37800

Corners of L's are identified uniquely in this case, but line segment lengths can vary.

Submissions are judged against all 57 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ThreeLLogo with a public method long long countWays(vector<string> grid) · 57 test cases · 2 s / 256 MB per case

Submitting as anonymous