Problem p02301 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

typedef complex<double> C;
typedef pair<C, C> pp;
typedef vector<C> VP;
typedef vector<pp> VPP;
#define eq(a, b) (fabs(a - b) < eps)
#define veq(a, b) (eq(a.real(), b.real()) && eq(a.imag(), b.imag()))
const C O{0, 0};

void In(C &p) {
  double x, y;
  cin >> x >> y;
  p = C(x, y);
}

void Out(C p) { cout << (int)p.real() << ' ' << (int)p.imag() << endl; }

double Dot(C p, C q) { return p.real() * q.real() + p.imag() * q.imag(); }

double Det(C p, C q) { return p.real() * q.imag() - q.real() * p.imag(); }

double Diameter(VP p) {
  int n = p.size(), I = 0, J = 0;
  for (int i = 1; i < n; i++) {
    if (p[i].imag() > p[I].imag())
      I = i;
    if (p[i].imag() < p[J].imag())
      J = i;
  }
  double res = abs(p[I] - p[J]);
  int i = I, j = J;
  do {
    if (Det(p[(i + 1) % n] - p[i], p[(j + 1) % n] - p[j]) > 0)
      j = (j + 1) % n;
    else
      i = (i + 1) % n;
    if (abs(p[i] - p[j]) > res)
      res = abs(p[i] - p[j]);
  } while (i != I || j != J);
  return res;
}

int n, q;
VP a;
C x;

int main() {
  cin >> n;
  a = VP(n);
  for (auto &i : a)
    In(i);
  cout << syosu(9) << Diameter(a) << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <typeinfo>
#include <vector>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 25;
const double pi = acos(-1);
const double eps = 1e-8;
const vi emp;

double add_double(double a, double b) {
  if (abs(a + b) < eps * (abs(a) + abs(b)))
    return 0;
  return a + b;
}

struct point {
  double x, y;
  point operator+(point p) {
    return point{add_double(x, p.x), add_double(y, p.y)};
  }
  point operator-(point p) {
    return point{add_double(x, -p.x), add_double(y, -p.y)};
  }
  point operator*(double p) { return point{x * p, y * p}; }
  point operator/(double p) {
    if (!p)
      return point{0, 0};
    return point{x / p, y / p};
  }
  bool operator==(point p) {
    return fabs(add_double(x, -p.x)) < eps && fabs(add_double(y, -p.y)) < eps;
  }
  bool operator<(point p) {
    if (fabs(x - p.x) > eps)
      return x < p.x;
    return y < p.y;
  }
};

typedef pair<point, point> pp;
typedef vector<point> VP;
const point O{0, 0};

class Geom {
public:
  double Length(point x, point y) {
    point z = y - x;
    return z.x * z.x + z.y * z.y;
  }
  double IP(point p, point q) { return p.x * q.x + p.y * q.y; }
  double CP(point p, point q) { return p.x * q.y - q.x * p.y; }
  double Diameter_Polygon(VP p) {
    double ans = 0;
    for (VP::iterator i = p.begin(); i != p.end(); i++) {
      for (VP::iterator j = p.begin(); j != i; j++) {
        ans = max(ans, Length(*i, *j));
      }
    }
    return ans;
  }
  void Point_in(point &p) { cin >> p.x >> p.y; }
  void Point_out(point p) { cout << p.x << ' ' << p.y << endl; }
};

int N;
VP p, ans;

int main() {
  cout << syosu(10);
  Geom geo;
  cin >> N;
  p = VP(N);
  for (VP::iterator i = p.begin(); i != p.end(); i++)
    geo.Point_in(*i);
  cout << sqrt(geo.Diameter_Polygon(p)) << endl;
}