1140D.md (1700B)
1 Source: https://codeforces.com/problemset/problem/1140/D 2 3 D. Minimum Triangulation 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given a regular polygon with $n$ vertices labeled from $1$ to $n$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices. 22 23 Calculate the minimum weight among all triangulations of the polygon. 24 25 Input 26 27 The first line contains single integer $n$ ($3 \le n \le 500$) — the number of vertices in the regular polygon. 28 29 Output 30 31 Print one integer — the minimum weight among all triangulations of the given polygon. 32 33 Examples 34 35 Input 36 37 ``` 38 3 39 ``` 40 41 Output 42 43 ``` 44 6 45 ``` 46 47 Input 48 49 ``` 50 4 51 ``` 52 53 Output 54 55 ``` 56 18 57 ``` 58 59 Note 60 61 According to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $P$ into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is $P$. 62 63 In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $1 \cdot 2 \cdot 3 = 6$. 64 65 In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $1-3$ so answer is $1 \cdot 2 \cdot 3 + 1 \cdot 3 \cdot 4 = 6 + 12 = 18$.