結果
問題 |
No.2331 Maximum Quadrilateral
|
ユーザー |
![]() |
提出日時 | 2023-07-25 00:12:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 172 ms / 2,000 ms |
コード長 | 3,172 bytes |
コンパイル時間 | 2,035 ms |
コンパイル使用メモリ | 196,256 KB |
最終ジャッジ日時 | 2025-02-15 18:47:27 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; // vector OA = (x, y) template <typename T> struct vec{ T x, y; vec (T xx=0, T yy=0) : x(xx), y(yy) {}; vec operator-() const { return vec(-x, -y); } vec& operator+=(const vec &w) { x += w.x; y += w.y; return *this; } vec& operator-=(const vec &w) { x -= w.x; y -= w.y; return *this; } vec operator+(const vec &w) const { vec res(*this); return res += w; } vec operator-(const vec &w) const { vec res(*this); return res-=w; } }; //Inner product of vectors v and w template <typename T> T dot(vec<T> v, vec<T> w){ return v.x * w.x + v.y * w.y; } //Outer product of vector v and w template <typename T> T outer(vec<T> v, vec<T> w){ return v.x * w.y - w.x * v.y; } //size of triangle ABC template <typename T> T heron(vec<T> &a, vec<T> &b, vec<T> &c){ return abs(outer(b-a, c-a)); } //Convex Hull(Smallest Convex set containing all given vecs) //Grahum Scan (O(NlogN)) template <typename T> vector<vec<T>> convex_hull(vector<vec<T>> P){ sort(P.begin(), P.end(), [](vec<T> &p1, vec<T> &p2) { if (p1.x != p2.x) return p1.x < p2.x; return p1.y < p2.y; }); int N=P.size(), k=0, t; vector<vec<T>> res(N*2); for (int i=0; i<N; i++){ while(k > 1 && outer(res[k-1]-res[k-2], P[i]-res[k-1]) <= 0) k--; res[k] = P[i]; k++; } t = k; for (int i=N-2; i>=0; i--){ while(k > t && outer(res[k-1]-res[k-2], P[i]-res[k-1]) <= 0) k--; res[k] = P[i]; k++; } res.resize(k-1); return res; } //distance between line PQ and point R template <typename T> T dist_line_point(vec<T> &p, vec<T> &q, vec<T> &r){ // ax+by+c=0 T a = (q.y-p.y), b = (p.x-q.x), c = -p.x*q.y + p.y*q.x; cout << a << " " << b << " " << c << endl; return abs(a*r.x+b*r.y+c) / sqrt(a*a+b*b); }; //judge if line AB intersects line CD template <typename T> bool intersect(vec<T> &a, vec<T> &b, vec<T> &c, vec<T> &d){ T s, t; s = outer(b-a, c-a); t = outer(b-a, d-a); if (s == 0 && t == 0){ if (max(a.x, b.x)<min(c.x, d.x) || max(a.y, b.y)<min(c.y, d.y) || min(a.x, b.x)>max(c.x, d.x) || min(a.y, b.y)>max(c.y, d.y)) return 0; else return 1; } if ((s > 0 && t > 0) || (s < 0 && t < 0)) return 0; s = outer(d-c, a-c); t = outer(d-c, b-c); if ((s > 0 && t > 0) || (s < 0 && t < 0)) return 0; return 1; } int main(){ ll N, x, y, u, l, ans=0; cin >> N; vector<vec<ll>> p(N); for (int i=0; i<N; i++){ cin >> x >> y; p[i] = vec(x, y); } for (int i=0; i<N; i++){ for (int j=i+1; j<N; j++){ l = -1e18, u = -1e18; for (int k=0; k<N; k++){ if (i == k || j == k) continue; //upper side if (outer(p[j]-p[i], p[k]-p[i]) > 0) u = max(u, heron(p[i], p[j], p[k])); else l = max(l, heron(p[i], p[j], p[k])); ans = max(ans, l+u); } } } cout << ans << endl; return 0; }