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

Code

# Read the number of vertices
n = int(input())

# Read the vertices
vertices = []
for _ in range(n):
    x, y = map(int, input().split())
    vertices.append((x, y))

# Close the polygon by appending the first vertex at the end
vertices.append(vertices[0])

# Calculate the double of the area using the Shoelace formula
area_double = 0
for i in range(n):
    x1, y1 = vertices[i]
    x2, y2 = vertices[i + 1]
    area_double += x1 * y2 - y1 * x2

# Output the absolute value of the doubled area
print(abs(area_double))

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