CSES - Aalto Competitive Programming 2024 - wk10 - Mon - Results
Submission details
Task:Polygon area
Sender:esya_rae
Submission time:2024-11-11 16:58:03 +0200
Language:Python3 (PyPy3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.04 sdetails

Code

import sys
import math

input = sys.stdin.readline



class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y


class Line:
    def __init__(self, a, b):
        self.a = a
        self.b = b

def cross_product(p, q):
    # x1y2 − x2y1
    return p.x * q.y - p.y * q.x


n = int(input())
polygon_lines = []

x, y = map(int, input().split())
area = 0
prev_p = Point(x, y)
prev_0 = prev_p

for i in range(n - 1):
    x, y = map(int, input().split())
    cur_p = Point(x, y)
    area += cross_product(prev_p, cur_p)
    prev_p = cur_p

area += cross_product(prev_p, prev_0)

print(abs(area))


#x1y2−x2y1+x2y3−x3y2+x3y4−x4y3+x4y1−x1y4,




Test details

Test 1

Verdict: ACCEPTED

input
100
-7 -19
91 77
100 100
64 60
...

correct output
43582

user output
43582

Test 2

Verdict: ACCEPTED

input
1000
365625896 -113418831
278762563 38777445
250367343 -96991975
175866909 -129766978
...

correct output
4053466653883387139

user output
4053466653883387139

Test 3

Verdict: ACCEPTED

input
4
-1000000000 -1000000000
-1000000000 1000000000
1000000000 1000000000
1000000000 -1000000000

correct output
8000000000000000000

user output
8000000000000000000