ExtendableTriangles
TCO09 Round 2 · 2009-02-24 · by ivan_metelsky
Problem Statement
Consider a rectangular grid of points on a plane with N rows and M columns. Each of the points is colored in one of three possible colors: red, green or blue. If we take any three distinct points (even those lying on the same straight line) and join them by line segments, we'll obtain a triangle (possibly degenerate). Such a triangle is called beautiful if all its vertices have distinct colors.
A beautiful triangle A is called extendable if there exists a beautiful triangle B such that A and B have two common vertices and the area of B is strictly greater than the area of A. Note that the area of a degenerate triangle is equal to 0.
You will be given a
Constraints
- grid will contain between 1 and 50 elements, inclusive.
- Each element of grid will contain between 1 and 50 characters, inclusive.
- All elements of grid will contain the same number of characters.
- Each element of grid will contain only characters 'R', 'G' and 'B'.
{"RGB"}
Returns: 0
There's only one degenerate triangle and it's not extendable.
{"RGB",
"RGB"}
Returns: 6
There are 8 beautiful triangles and 6 of them are extendable. These triangles are listed below ('X' means triangle vertex): XXX ... XX. ..X .XX X.. ... XXX ..X XX. X.. .XX
{"RRRRRRRR",
"GGGGBBBB",
"RRRRRRRR"}
Returns: 240
There are 256 beatiful triangles. The 16 of them which contain the leftmost green and the rightmost blue points are not extendable. Therefore the answer is 256 - 16 = 240.
{"RBRBRBRB",
"BRBRBRBR",
"RBRBRBRB",
"BRBRBRBR",
"RRRRRRRR",
"BBBBBBBB",
"RRRRBBBB",
"BBBBRRRR"}
Returns: 0
There are no beautiful triangles because there are no green points.
{"RGB",
"RBG",
"GRB",
"GBR",
"BRG",
"BGR"}
Returns: 208
Submissions are judged against all 150 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ExtendableTriangles with a public method int getCount(vector<string> grid) · 150 test cases · 2 s / 256 MB per case