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

#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define exist(s, e) ((s).find(e) != (s).end())
#define range(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) range(i, 0, n)
#define clr(a, b) memset((a), (b), sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 29;

// ??\\??? ????????¨???
template <class T> bool operator==(T a, T b) { return abs(a - b) < eps; }
template <class T> bool operator<(T a, T b) { return a < b - eps; }
template <class T> bool operator<=(T a, T b) { return a < b + eps; }
template <class T> int sig(T r) {
  return (r == 0 || r == -0) ? 0 : r > 0 ? 1 : -1;
}
#define X real()
#define Y imag()

typedef bool B;
typedef long double D;
typedef complex<D> P;

P p[310];

int main(void) {
  int n;
  while (cin >> n, n) {
    D ix, iy;
    rep(i, n) {
      cin >> ix >> iy;
      p[i].real(ix), p[i].imag(iy);
    }
    int ans = 1;
    rep(i, n) rep(j, n) {
      if (i <= j)
        continue;
      D d = norm(p[j] - p[i]);
      if (d > 4.0)
        continue;
      P v = (p[j] - p[i]) / P(2.0, 0.0);
      D s = sqrt((1.0 - norm(v)) / norm(v));
      P cnt1 = p[i] + v + s * P(v.imag(), -v.real());
      int num = 2;
      rep(k, n) {
        if (k == i || k == j)
          continue;
        if (norm(p[k] - cnt1) < 1.0)
          num++;
      }
      ans = max(ans, num);
      P cnt2 = p[i] + v + s * P(-v.imag(), v.real());
      int num2 = 2;
      rep(k, n) {
        if (k == i || k == j)
          continue;
        if (norm(p[k] - cnt2) < 1.0)
          num2++;
      }
      ans = max(ans, num2);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define exist(s, e) ((s).find(e) != (s).end())
#define range(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) range(i, 0, n)
#define clr(a, b) memset((a), (b), sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 29;

// ??\\??? ????????¨???
template <class T> bool operator==(T a, T b) { return abs(a - b) < eps; }
template <class T> bool operator<(T a, T b) { return a < b - eps; }
template <class T> bool operator<=(T a, T b) { return a < b + eps; }
template <class T> int sig(T r) {
  return (r == 0 || r == -0) ? 0 : r > 0 ? 1 : -1;
}
#define X real()
#define Y imag()

typedef bool B;
typedef long double D;
typedef complex<D> P;

P p[310];

int main(void) {
  int n;
  while (cin >> n, n) {
    double ix, iy;
    rep(i, n) {
      scanf("%lf %lf", &ix, &iy);
      p[i].real(ix), p[i].imag(iy);
    }
    int ans = 1;
    rep(i, n) rep(j, n) {
      if (i == j)
        continue;
      D d = norm(p[j] - p[i]);
      if (d > 4.0)
        continue;
      P v = (p[j] - p[i]) / P(2.0, 0.0);
      D s = sqrt((1.0 - norm(v)) / norm(v));
      P cnt1 = p[i] + v + s * P(v.imag(), -v.real());
      int num = 2;
      rep(k, n) {
        if (k == i || k == j)
          continue;
        if (norm(p[k] - cnt1) < 1.0)
          num++;
      }
      ans = max(ans, num);
      P cnt2 = p[i] + v + s * P(-v.imag(), v.real());
      int num2 = 2;
      rep(k, n) {
        if (k == i || k == j)
          continue;
        if (norm(p[k] - cnt2) < 1.0)
          num2++;
      }
      ans = max(ans, num2);
    }
    printf("%d\\n", ans);
  }
  return 0;
}