| Task: | Polygon area |
| Sender: | duongha |
| Submission time: | 2025-11-10 16:32:34 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
# define MAXSUM 1000001
typedef long long ll;
const ll INF = 1e18;
const int MAXN1 = 1e3 + 1;
const int MAXN2 = 1e5;
struct Point {
ll x, y;
};
ll n;
Point a[MAXN1];
ll calculatePoly (Point a[MAXN1], ll n) {
ll c = 0;
int j = n;
for (int i = 1; i <= n; i++) {
c += (a[i].x + a[j].x) * (a[j].y - a[i].y);
j = i;
}
return abs(c);
}
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y;
}
cout << calculatePoly(a, n);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
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 |
