Task: | Polygon area |
Sender: | laluj |
Submission time: | 2024-11-11 16:32:50 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.00 s | details |
Code
#include <iostream> #include <vector> #include <cmath> using namespace std; struct Point { long long x, y; }; long long polygonArea(const vector<Point>& vertices) { int n = vertices.size(); long long area = 0; for (int i = 0; i < n; i++) { int j = (i + 1) % n; area += vertices[i].x * vertices[j].y - vertices[i].y * vertices[j].x; } return abs(area); } int main() { int n; cin >> n; vector<Point> vertices(n); for (int i = 0; i < n; i++) { cin >> vertices[i].x >> vertices[i].y; } cout << polygonArea(vertices) << endl; return 0; }
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 |