Kattis - Polygon Area

Author: Neo Wang

Problem Statement

We can use the shoelace theorem to find the area of the polygon.

Recall that the sign of the resulting area determines the direction in which the vertices are given. For our implementation, the vertices are given clockwise if the area is negative, and counterclockwise otherwise.

Implementation

Time Complexity: O(N)\mathcal{O}(N)

#include <bits/stdc++.h> // see /general/running-code-locally
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!