CCC '22 S4 - Good Triplets

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 3.0s
Memory limit: 1G

Author:
Problem types
Canadian Computing Competition: 2022 Stage 1, Senior #4

Andrew is a very curious student who drew a circle with the center at (0,0) and an integer circumference of C3. The location of a point on the circle is the counter-clockwise arc length from the right-most point of the circle.

Andrew drew N3 points at integer locations. In particular, the ith point is drawn at location Pi (0PiC1). It is possible for Andrew to draw multiple points at the same location.

A good triplet is defined as a triplet (a,b,c) that satisfies the following conditions:

  • 1a<b<cN.
  • The origin (0,0) lies strictly inside the triangle with vertices at Pa, Pb, and Pc. In particular, the origin is not on the triangle's perimeter.

Lastly, two triplets (a,b,c) and (a,b,c) are distinct if aa, bb, or cc.

Andrew, being a curious student, wants to know the number of distinct good triplets. Please help him determine this number.

Input Specification

The first line contains the integers N and C, separated by one space.

The second line contains N space-separated integers. The ith integer is Pi (0PiC1).

The following table shows how the available 15 marks are distributed.

Marks AwardedNumber of PointsCircumferenceAdditional Constraints
3 marks3N2003C106None
3 marks3N1063C6000None
6 marks3N1063C106P1,P2,,PN are all distinct (i.e., every location contains at most one point)
3 marks3N1063C106None

Output Specification

Output the number of distinct good triplets.

Sample Input

Copy
8 10
0 2 5 5 6 9 0 0

Output for Sample Input

Copy
6

Explanation of Output for Sample Input

Andrew drew the following diagram.

The origin lies strictly inside the triangle with vertices P1, P2, and P5, so (1,2,5) is a good triplet. The other five good triplets are (2,3,6), (2,4,6), (2,5,6), (2,5,7), and (2,5,8).


Comments


  • 1
    jfan27  commented on Sept. 10, 2024, 2:31 a.m. edit 2

    Time complexity of O(N3) gives tle on everything but batch 1 btw