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

#include <algorithm>
#include <assert.h>
#include <complex>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef complex<double> Point;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int n;
int ans;
double R;
Point points[3000];
pair<double, int> radian[30000];
bool used[3000];

int calc(int s) {
  int ret = 1;
  int m = 0;
  REP(i, n) {
    double d = abs(points[s] - points[i]) / 2.0;
    if (i == s || d * 2.0 > R * 2) {
      continue;
    }
    Point center = (points[s] + points[i]) / 2.0;
    Point vect = (points[i] - points[s]) * Point(0, -1);
    vect /= abs(vect);
    double l = sqrt(R * R - d * d);
    Point c1 = center + vect * l;
    Point c2 = center - vect * l;
    double arg1 = arg(c1 - points[s]) - EPS;
    double arg2 = arg(c2 - points[s]) + EPS;
    radian[m++] = pair<double, int>(arg1 + 0 * PI, (i + 1));
    radian[m++] = pair<double, int>(arg2 + 0 * PI, -(i + 1));
  }
  if (m / 2 < ans - 1) {
    return 0;
  }
  sort(radian, radian + m);
  MEMSET(used, false);
  int lsum = 1;
  REP(iter, 2) {
    REP(i, m) {
      int index = abs(radian[i].second) - 1;
      bool start = radian[i].second > 0 ? true : false;
      if (used[index] && !start) {
        used[index] = false;
        lsum--;
      } else if (!used[index] && start) {
        used[index] = true;
        lsum++;
      }
      ret = max(ret, lsum);
    }
  }
  return ret;
}

int main() {
  R = 1.0;
  while (scanf("%d", &n), n) {
    REP(i, n) {
      double x, y;
      scanf("%lf %lf", &x, &y);
      points[i] = Point(x, y);
    }
    ans = 0;
    REP(i, n) { ans = max(ans, calc(i)); }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <complex>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef complex<double> Point;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int n;
int ans;
double R;
Point points[3000];
pair<double, int> radian[30000];
bool used[3000];

int calc(int s) {
  int ret = 1;
  int m = 0;
  REP(i, n) {
    double d = abs(points[s] - points[i]) / 2.0;
    if (i == s || d * 2.0 > R * 2) {
      continue;
    }
    Point center = (points[s] + points[i]) / 2.0;
    Point vect = (points[i] - points[s]) * Point(0, -1);
    vect /= abs(vect);
    double l = sqrt(R * R - d * d);
    Point c1 = center + vect * l;
    Point c2 = center - vect * l;
    double arg1 = arg(c1 - points[s]) - EPS;
    double arg2 = arg(c2 - points[s]) + EPS;
    radian[m++] = pair<double, int>(arg1 + 0 * PI, (i + 1));
    radian[m++] = pair<double, int>(arg2 + 0 * PI, -(i + 1));
  }
  if (m / 2 < ans - 1) {
    return 0;
  }
  sort(radian, radian + m);
  MEMSET(used, false);
  int lsum = 1;
  REP(iter, 2) {
    REP(i, m) {
      int index = abs(radian[i].second) - 1;
      bool start = radian[i].second > 0 ? true : false;
      if (used[index] && !start) {
        used[index] = false;
        lsum--;
      } else if (!used[index] && start) {
        used[index] = true;
        lsum++;
      }
      ret = max(ret, lsum);
    }
  }
  return ret;
}

int main() {
  R = 1.0;
  while (scanf("%d %lf", &n), n) {
    REP(i, n) {
      double x, y;
      scanf("%lf %lf", &x, &y);
      points[i] = Point(x, y);
    }
    ans = 0;
    REP(i, n) { ans = max(ans, calc(i)); }
    printf("It is possible to cover %d points.\\n", ans);
  }
}