Subpolygon
SRM 736 *TCO19* · 2018-08-14 · by majk
Problem Statement
This problem has a non-standard time limit of 10 seconds.
Let P be a (strictly) convex polygon, let V be the set of vertices of P, and let W be any subset of V of size 3 or more. Then, the convex hull of W is called a subpolygon of P.
For instance, let (0,0), (2,0), (3,3), (0,2) be the vertices of a convex polygon P. This polygon has five subpolygons: the polygon itself and four triangles.
You are given a special convex polygon P on 4n vertices, all having integer coordinates. Calculate the sum of areas of all subpolygons of P. Express the answer as a fraction A/B, where gcd(A,B) = 1. Let B-1 be the multiplicative inverse of B modulo 998244353. Return A*B-1 modulo 998244353.
The procedure for generating the input polygon P is as follows.
You are given an
Let P[0] be an arbitrary point in the plane. For all i from 1 to 4n, set P[i] = P[i-1] + T[i-1]. I.e., if P[i-1] has coordinates (x1,y1) and T[i-1] has coordinates (x2,y2), the new point P[i] has coordinates (x1+x2,y1+y2).
The polygon P you should process is the polygon with vertices at P[0], P[1], ..., P[4n-1]. Note that P is always a simple convex polygon, and that the answer you should return does not depend on the choices you made during the construction. Also note that the above process sets P[4n] to the same point as P[0].
Constraints
- n will be between 1 and 125,000, inclusive.
1 Returns: 3
One possible polygon P is {(0,0),(1,0),(0,1),(1,1)}. It has five subpolygons: P itself has area 1, and each of the four triangles has area 1/2. The sum of these areas is 3.
2 Returns: 1650
For n = 2 we may choose that T = {(2,0), (1,1), (0,2), (-1,1), (-2,0), (-1,-1), (0,-2), (1,-1)} and that P[0] = (0,0). These two choices will then produce the polygon P = {(0,0), (2,0), (3,1), (3,3), (2,4), (0,4), (-1,3), (-1,1)}. This polygon P has 219 subpolygons. All these sub-polygons happen to have integral areas. The number of sub-polygons with area 1, 2, 3, ..., 14 is {8, 8, 20, 12, 8, 34, 16, 14, 28, 22, 20, 20, 8, 1}.
35 Returns: 132946800
Do not forget to calculate the result modulo 998244353.
124999 Returns: 483134074
125000 Returns: 977938101
Submissions are judged against all 42 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Subpolygon with a public method int sumOfAreas(int n) · 42 test cases · 2 s / 256 MB per case