DMPG '18 G5 - Triangles

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Given N points with coordinates (x_1, y_1), (x_2, y_2), \dots, (x_N, y_N), determine the largest possible area of a triangle formed by three of these N points.

Constraints

For all subtasks,
|x_i|, |y_i| \le 10\,000 for all 1 \le i \le N
All coordinates are guaranteed to be distinct.

Subtask 1 [30%]

3 \le N \le 500

Subtask 2 [70%]

3 \le N \le 4\,000

Input Specification

The first line will contain a single integer, N.
The next N lines will each contain two space separated integers x_i and y_i, the coordinates of the i^{\text{th}} point.

Output Specification

Output a single number, the largest possible area. Your answer will be judged as correct if your area has an absolute error of no more than 10^{-3}.

Sample Input 1

7
2 13
5 5
-6 3
0 0
7 10
-8 4
2 3

Sample Output 1

56.000

Sample Input 2

3
1 5
4 5
7 5

Sample Output 2

0.000

Comments


  • 4
    r3mark  commented on Aug. 20, 2018, 1:04 p.m.

    A word of warning to those who use the well-known \mathcal{O}(N) rotating callipers solution for this problem: it turns out that this solution is incorrect. I have added a few more test cases to try to hack this solution (although I will not rejudge already accepted solutions). For further details about this, see here.


    • -1
      harry7557558  commented on March 9, 2020, 6:20 a.m.

      I just use three loops for all points on the convex hull and got AC.


      • 3
        Kirito  commented on March 9, 2020, 1:33 p.m.

        The judges were replaced with much faster ones, so it looks like we will need to adjust the time limit.


  • -5
    DarthVader336  commented on April 29, 2018, 11:51 p.m. edited

    This comment is hidden due to too much negative feedback. Click here to view it.


  • -3
    DarthVader336  commented on April 29, 2018, 3:03 p.m.

    Just use Heron's formula and three loops!


    • 1
      harry7557558  commented on March 9, 2020, 5:11 a.m. edit 3

      You don't have to use Heron's formula. Given three points (x_0,y_0), (x_1,y_1), (x_2,y_2), \frac{1}{2}((x_1-x_0)(y_2-y_0)-(x_2-x_0)(y_1-y_0)) will give you the area of the triangle defined by these points.


    • 1
      wleung_bvg  commented on April 29, 2018, 3:06 p.m.

      In theory, that should only pass the first subtask. Though the bounds might not be strong enough to prevent that solution from passing...


      • -4
        DarthVader336  commented on April 30, 2018, 12:33 a.m.

        Can you give me a hint on how to pass the second subtask?


      • -2
        DarthVader336  commented on April 29, 2018, 11:39 p.m.

        Good point! I passed the first batch, but I got TLE on the second.