Statistics

Problem Statement for "Subpolygon"

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 int n. Consider the square with vertices (n,0), (0,n), (-n,0), (0,-n). On the boundary of this square there are exactly 4n points with integer coordinates. (This includes all four corners of the square.) Start at an arbitrary one of these 4n points and label them T[0] through T[4n-1] in counter-clockwise order.

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].

Definition

Class:
Subpolygon
Method:
sumOfAreas
Parameters:
int
Returns:
int
Method signature:
int sumOfAreas(int n)
(be sure your method is public)

Constraints

  • n will be between 1 and 125,000, inclusive.

Examples

  1. 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. 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}.

  3. 35

    Returns: 132946800

    Do not forget to calculate the result modulo 998244353.

  4. 124999

    Returns: 483134074

  5. 125000

    Returns: 977938101

  6. 3

    Returns: 184527

  7. 4

    Returns: 10879320

  8. 5

    Returns: 461374023

  9. 6

    Returns: 92275762

  10. 7

    Returns: 763365104

  11. 8

    Returns: 687857166

  12. 9

    Returns: 754629825

  13. 10

    Returns: 452624163

  14. 47

    Returns: 701128126

  15. 69

    Returns: 109996738

  16. 135

    Returns: 87107455

  17. 792

    Returns: 550636463

  18. 4023

    Returns: 141817167

  19. 12306

    Returns: 847664327

  20. 118293

    Returns: 853615835

  21. 100001

    Returns: 421818861

  22. 102343

    Returns: 973189880

  23. 89232

    Returns: 413306507

  24. 16383

    Returns: 286812279

  25. 16384

    Returns: 221046812

  26. 16385

    Returns: 259711468

  27. 32767

    Returns: 735166269

  28. 32768

    Returns: 101030739

  29. 32769

    Returns: 198742540

  30. 65535

    Returns: 344999661

  31. 65536

    Returns: 387004040

  32. 65537

    Returns: 452079417

  33. 65538

    Returns: 447636276

  34. 65539

    Returns: 863714471

  35. 65534

    Returns: 265308248

  36. 65533

    Returns: 737340991

  37. 65532

    Returns: 793754674

  38. 65540

    Returns: 335609374

  39. 65541

    Returns: 674724179

  40. 65542

    Returns: 149328308

  41. 119320

    Returns: 496234584

  42. 118432

    Returns: 195431473


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: