Submission details
Task:Polygon area
Sender:rikachu
Submission time:2025-11-10 16:32:04 +0200
Language:C++ (C++17)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define IOS ios_base::sync_with_stdio(0), cin.tie(0)
const int INF = 1001001001;
const int MAXN = 100'000;
const char br = '\n';
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x)                                                                 \
	{                                                                      \
		++recur_depth;                                                 \
		auto x_ = x;                                                   \
		--recur_depth;                                                 \
		cerr << string(recur_depth, '\t') << "\e[91m" << __func__      \
		     << ":" << __LINE__ << "\t" << #x << " = " << x_           \
		     << "\e[39m" << endl;                                      \
	}
#else
#define dbg(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream &>::type
operator<<(Ostream &os, const Cont &v) {
	os << "[";
	for (auto &x : v) {
		os << x << ", ";
	}
	return os << "]";
}

// === Debug macro ends here ===

// print pair, vector
template <typename Ostream, typename... Ts>
Ostream &operator<<(Ostream &os, const pair<Ts...> &p) {
	return os << "{" << p.first << ", " << p.second << "}";
}
template <typename T> ostream &operator<<(ostream &s, vector<T> t) {
	for (const T &v : t) {
		cout << v << " ";
	}
	return s;
}

int nxt() {
	int x;
	cin >> x;
	return x;
}

using C = long long;
using pt = complex<C>;
#define X real()
#define Y imag()

C cross(pt a, pt b) { return (conj(a) * b).Y; }

C area(vector<pt>& pts) {
	
	C res = 0;
	for (size_t i = 0; i < pts.size() - 1; i++) {
		auto pt0 = pts[i];
		auto pt1 = pts[i+1];
		res += cross(pt0, pt1);
	}
	return abs(res);

}

int main() {
	IOS;

	int n = nxt();
	vector<pt> pts(n);
	for (size_t i = 0; i < pts.size(); i++) {
		C a, b;
		cin >> a >> b;
		pts[i] = {a, b};
	}
	pts.push_back(pts[0]);

	auto res = area(pts);

	cout << res << br;

	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