| Task: | Polygon area |
| Sender: | discape |
| Submission time: | 2025-11-10 16:37:13 +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
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#ifdef DO_DBG
namespace std { // these allow printing all pairs, vectors, sets and maps, recursively too
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p)
{ return os << '(' << p.first << ", " << p.second << ')'; }
template <typename T> requires (!std::is_convertible_v<T, const char*>) && ranges::range<T> && (!is_same_v<T, string>)
ostream& operator<<(ostream &os, const T &p) { os << "{ "; for (auto& x : p) os << x << ' '; os << '}'; return os; }
} // end namespace std
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", _dbg_out(__VA_ARGS__)
template <typename T> void _dbg_out(const T &t) { cerr << t << "]\n"; }
template <typename T, typename... Args> void _dbg_out(const T &t, const Args &...args) { cerr << t << ", "; _dbg_out(args...); }
#else
#define dbg(...)
#endif
template <typename... Args> void read(Args&... args) { ((cin >> args), ...); }
template <typename T> using v = vector<T>;
typedef long long ll; typedef long double ld; typedef v<ll> vi; typedef pair<ll, ll> pii; // this template is kactl compatible
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin.exceptions(cin.failbit);
#define rep(i,a,b) for (ll i = a; i < b; i++)
#define rp(n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sq(x) ((x)*(x))
#define d(...) ll __VA_ARGS__; read(__VA_ARGS__);
#define dv(x, n) vi x(n); for (size_t i = 0; i < n; i++) cin >> x[i];
#define even(x) ((x)%2==0)
#define odd(x) ((x)%2!=0)
#define sz(s) ((ll)s.size())
#define dist(v,it) distance(v.begin(),it)
typedef complex<ll> Pi;
typedef complex<ld> Pr;
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).imag()
// clang-format on
// area of polygon
int main() {
ios;
d(n);
v<Pi> points(n);
rp(n) {
d(x, y);
points[i] = Pi(x, y);
}
ll area = 0;
rep(i, 0, n) { area += cross(points[i], points[(i + 1) % n]); }
// we output 2x the area
cout << abs(area) << '\n';
}
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 |
