Problem p02556 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
#define absd(x) (x < 0 ? -(x) : x)
#define pow2(x) ((x) * (x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define replr(i, s, n) for (int i = n; i >= s; --i)
#define repf(i, s, n, j) for (int i = s; i <= n; i += j)
#define repe(e, obj) for (auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X, Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i, n, val)                                                      \\
  for (int i = 0; i < n; ++i)                                                  \\
    cout << val << " ";                                                        \\
  cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-7

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P>> pvqueue;

ll cross(P base, P x1, P x2) {
  return (x1.first - base.first) * (x2.second - base.second) -
         (x1.second - base.second) * (x2.first - base.first);
}

double dist(P x1, P x2) {
  return sqrt(
      (double)(pow2(x2.first - x1.first) + pow2(x2.second - x1.second)));
}

double poww2(P x1, P x2) {
  return ((pow2(x2.first - x1.first) + pow2(x2.second - x1.second)));
}

vector<P> convex_hull(vector<P> ps) {
  int n = ps.size();
  int k = 0;
  sort(ALL(ps));
  vector<P> qs(n * 2);
  rep(i, n) {
    while (k > 1 && (cross(qs[k - 2], qs[k - 1], ps[i]) <= 0))
      k--;
    qs[k++] = ps[i];
  }
  int t = k;
  repr(i, n - 1) {
    while (k > t && (cross(qs[k - 2], qs[k - 1], ps[i]) <= 0))
      k--;
    qs[k++] = ps[i];
  }
  qs.resize(k - 1);
  return qs;
}

int main() {
  int n;
  cin >> n;
  vector<P> A;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    A.push_back(P(x, y));
  }

  auto manh = [&](P &p1, P &p2) {
    return abs(p1.first - p2.first) + abs(p1.second - p2.second);
  };
  vector<P> Ac = convex_hull(A);
  ll ans = 0;
  rep(i, Ac.size()) {
    for (int j = 0; j < i; j++) {
      ans = max(ans, manh(Ac[i], Ac[j]));
    }
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; // MAX 9223372036854775807
double pi = 3.1415926535897932;
struct point {
  double x, y, val;
  point() {}
  point(double x, double y, double val) : x(x), y(y), val(val){};
  point(double x, double y) : x(x), y(y), val(0){};
};
struct vec {
  ll x, y;
  vec() {}
  vec(ll x, ll y) : x(x), y(y){};
  vec(point a, point b) : x(b.x - a.x), y(b.y - a.y){};
  ll size() { return x + y; };
};
// xの昇順で同じときyの昇順
bool cmp(const point &a, const point &b) {
  if (a.x == b.x)
    return a.y < b.y;
  else
    return a.x < b.x;
}
// 3点が一直線上にあるとtrue
bool threepoint(point a, point b, point c) {
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x) == 0;
}
// 先に一直線上にないか確認
point threepoint_circle(point a, point b, point c) {
  point p;
  double k = ((c.x - a.x) * (c.x - b.x) + (c.y - a.y) * (c.y - b.y)) /
             ((b.y - a.y) * (c.x - a.x) - (b.x - a.x) * (c.y - a.y));
  p.x = (a.x + b.x + k * (b.y - a.y)) / 2;
  p.y = (a.y + b.y - k * (b.x - a.x)) / 2;
  p.val = sqrt(p.x * p.x + p.y * p.y - a.x * b.x - a.y * b.y -
               k * a.x * (b.y - a.y) + k * a.y * (b.x - a.x));
  return p;
}
// 2円の交点　同じ円は除く
vector<point> circle_intersection(point c1, double r1, point c2, double r2) {
  vector<point> res;
  if (r1 + r2 == vec(c1, c2).size() || fabs(r1 - r2) == vec(c1, c2).size()) {
    point p(vec(c1, c2).x * r1 / vec(c1, c2).size() + c1.x,
            vec(c1, c2).y * r1 / vec(c1, c2).size() + c1.y);
    res.push_back(p);
  } else if (r1 + r2 > vec(c1, c2).size() &&
             fabs(r1 - r2) < vec(c1, c2).size()) {
    double di = vec(c1, c2).size() * vec(c1, c2).size();
    double li = (di + r1 * r1 - r2 * r2) / 2;
    point p1(c1.x + (li * (-c1.x + c2.x) +
                     (-c1.y + c2.y) * sqrt(di * r1 * r1 - li * li)) /
                        di,
             c1.y + (li * (-c1.y + c2.y) -
                     (-c1.x + c2.x) * sqrt(di * r1 * r1 - li * li)) /
                        di);
    res.push_back(p1);
    point p2(c1.x + (li * (-c1.x + c2.x) -
                     (-c1.y + c2.y) * sqrt(di * r1 * r1 - li * li)) /
                        di,
             c1.y + (li * (-c1.y + c2.y) +
                     (-c1.x + c2.x) * sqrt(di * r1 * r1 - li * li)) /
                        di);
    res.push_back(p2);
  }
  return res;
}
// ベクトルabとベクトルbcにおけるbcに対して時計回りの角cba
double arg(vec a, vec b) {
  if (a.x * b.y - a.y * b.x > 0)
    return acos((-a.x * b.x - a.y * b.y) / (a.size() * b.size())) * (-180) /
               pi +
           360;
  else
    return acos((-a.x * b.x - a.y * b.y) / (a.size() * b.size())) * 180 / pi;
}

// 凸包　左（同じなら下）から時計回りに出力
vector<point> convex_hull(vector<point> &v) {
  sort(v.begin(), v.end(), cmp);
  vector<point> res, res2;
  for (auto p : v) {
    if (res.size() < 2)
      res.push_back(p);
    else {
      while (arg(vec(res[res.size() - 2], res[res.size() - 1]),
                 vec(res[res.size() - 1], p)) > 180.00001 &&
             res.size() >= 2)
        res.pop_back();
      res.push_back(p);
    }
  }
  for (auto p : v) {
    if (res2.size() < 2)
      res2.push_back(p);
    else {
      while (arg(vec(res2[res2.size() - 2], res2[res2.size() - 1]),
                 vec(res2[res2.size() - 1], p)) < 179.99999 &&
             res2.size() >= 2)
        res2.pop_back();
      res2.push_back(p);
    }
  }
  rep(i, res2.size() - 2) { res.push_back(res2[res2.size() - i - 2]); }
  return res;
}
// 凸包における最遠点対
vector<pair<point, point>> convex_diameter(vector<point> &v) {
  ll st = 0;
  double mx = 0;
  vector<pair<point, point>> res;
  for (ll i = 1; i < v.size(); i++) {
    auto te = vec(v[st], v[i]);
    double tesize = te.size();
    if (tesize > mx) {
      mx = tesize;
      res.clear();
      res.emplace_back(v[st], v[i]);
    } else if (tesize == mx)
      res.emplace_back(v[st], v[i]);
    while (i - st >= 2) {
      auto te2 = vec(v[st + 1], v[i]);
      if (tesize < te2.size()) {
        tesize = te2.size();
        st++;
        if (te2.size() > mx) {
          mx = te2.size();
          res.clear();
          res.emplace_back(v[st], v[i]);
        } else if (te2.size() == mx)
          res.emplace_back(v[st], v[i]);
      } else
        break;
    }
  }
  return res;
}

int main() {
  // 凸包後の最遠点対http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B&lang=jp
  {
    ll n;
    cin >> n;
    vector<point> v;
    rep(i, n) {
      double x, y;
      cin >> x >> y;
      v.push_back({x, y});
    }
    auto ans = convex_diameter(v);
    auto an = vec(ans[0].first, ans[0].second);
    // cout<<fixed<<setprecision(12)<< an.size() <<endl;
    cout << ll(an.x + an.y) << endl;
  }

  return 0;
}