MaximalTriangle
SRM 547 · 2011-11-22 · by sdya
Problem Statement
The vertices of the polygon are labeled 1 through n in clockwise order. Two sets of diagonals are different if one of them contains a diagonal that is not present in the other one. Count all sets of (n-3) non-intersecting diagonals that produce an arrangement with the above property. Return that count modulo z.
Constraints
- n will be between 3 and 444, inclusive.
- z will be between 1 and 1,000,000,000 (10^9), inclusive.
4 1000000000 Returns: 0
There are two ways how to select a diagonal in a square. Each of them produces two triangles of equal size.
5 100 Returns: 5
There are five ways how to select two non-intersecting diagonals in a regular pentagon. Each of them produces an arrangement in which one triangle has a larger area than each of the other two.
6 1000003 Returns: 2
For a regular hexagon, some sets of diagonals produce a good set of triangles, and some do not.
10 1000000000 Returns: 1010
15 1000000000 Returns: 714340
Submissions are judged against all 30 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MaximalTriangle with a public method int howMany(int n, int z) · 30 test cases · 2 s / 256 MB per case