Task: | Polygon area |
Sender: | Farah |
Submission time: | 2024-11-11 17:22:16 +0200 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.04 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | ACCEPTED | 0.04 s | details |
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 |