alexjercan/bugnet huggingface dataset:
Problem p00712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

int cont;
void saiki(double rest, int a, int n, int st, vector<int> &bin) {

  if (fabs(rest) < 0.0000001) {
    cont++;
    return;
  }
  if (bin.size() == n)
    return;
  if (rest < 0)
    return;

  int sum = 1;
  rep(i, bin.size()) sum *= bin[i];

  for (int i = st;; i++) {
    if (sum * i <= a) {
      bin.push_back(i);
      saiki(rest - 1.0 / i, a, n, i, bin);
      bin.pop_back();
    } else {
      break;
    }
  }
}

int main() {
  while (1) {
    int p, q, a, n;
    cin >> p >> q >> a >> n;
    cont = 0;

    if (n == 0)
      break;

    vector<int> bin;
    int st = 1;
    double rest = (double)p / q;
    saiki(rest, a, n, st, bin);

    printf("%d\\n", cont);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

int cont;
void saiki(double rest, int a, int n, int st, vector<int> &bin) {

  if (fabs(rest) < 0.0000001) {
    cont++;
    return;
  }
  if (bin.size() == n)
    return;

  int sum = 1;
  rep(i, bin.size()) sum *= bin[i];

  for (int i = st;; i++) {
    if (sum * i <= a) {
      bin.push_back(i);
      saiki(rest - 1.0 / i, a, n, i, bin);
      bin.pop_back();
    } else {
      break;
    }
  }
}

int main() {
  while (1) {
    int p, q, a, n;
    cin >> p >> q >> a >> n;
    cont = 0;

    if (n == 0)
      break;

    vector<int> bin;
    int st = 1;
    double rest = (double)p / q;
    saiki(rest, a, n, st, bin);

    printf("%d\\n", cont);
  }
}
Problem p00712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef int lli;

lli P, Q, A, N, ans;

void rec(lli child, lli parent, lli th, lli pre) {
  if (th == N)
    return;
  for (lli i = min(pre, A / parent); i >= 1; --i) {
    lli nc = child * i + parent;
    lli np = parent * i;
    if (Q * nc > P * np)
      break;
    if (Q * nc == P * np)
      ++ans;
    else
      rec(nc, np, th + 1, i);
  }
}

int main() {
  while (cin >> P >> Q >> A >> N && (P | Q | A | N)) {
    ans = 0;
    rec(0, 1, 0, A);
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef long long lli;

lli P, Q, A, N, ans;

void rec(lli child, lli parent, lli th, lli pre) {
  if (th == N)
    return;
  for (lli i = min(pre, A / parent); i >= 1; --i) {
    lli nc = child * i + parent;
    lli np = parent * i;
    if (Q * nc > P * np)
      break;
    else if (Q * nc == P * np)
      ++ans;
    else
      rec(nc, np, th + 1, i);
  }
}

int main() {
  while (cin >> P >> Q >> A >> N && (P | Q | A | N)) {
    ans = 0;
    rec(0, 1, 0, A);
    cout << ans << endl;
  }
  return 0;
}
Problem p00712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <vector>
using namespace std;

int p, q, a, n;

int gcd(int a, int b) {
  return a % b ? gcd(b, a % b) : b;
} // Ååöñ
int lcm(int a, int b) { return a / gcd(a, b) * b; } // Å¬ö{

class Fraction {
public:
  int bo, shi;
  Fraction(int shi, int bo) : bo(bo), shi(shi){};
  Fraction(){};
};

Fraction my_plus(Fraction a, Fraction b) {
  if (a.shi == 0)
    return b;
  int new_bo = a.bo * b.bo;
  int new_shi = a.shi * (new_bo / a.bo) + b.shi * (new_bo / b.bo);
  return Fraction(new_shi, new_bo);
}
int ans = 0;

void dfs(int num, int now_bo, int mul, Fraction now) {
  if (p * now.bo < q * now.shi)
    return;
  if (num > n)
    return;
  if (mul > a)
    return;
  if (p * now.bo == q * now.shi) {
    ans++;
    return;
  }
  for (int i = now_bo; i <= 12000; i++) {

    if (mul * i > a)
      break;
    dfs(num + 1, i, mul * i, my_plus(now, Fraction(1, i)));
  }
}

int main() {
  while (cin >> p >> q >> a >> n && p != 0 && q != 0 && a != 0 && n != 0) {
    ans = 0;
    dfs(0, 1, 1, Fraction(0, 2));
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <vector>
using namespace std;

int p, q, a, n;

int gcd(int a, int b) {
  return a % b ? gcd(b, a % b) : b;
} // Ååöñ
int lcm(int a, int b) { return a / gcd(a, b) * b; } // Å¬ö{

class Fraction {
public:
  int bo, shi;
  Fraction(int shi, int bo) : bo(bo), shi(shi){};
  Fraction(){};
};

Fraction my_plus(Fraction a, Fraction b) {
  if (a.shi == 0)
    return b;
  int new_bo = lcm(a.bo, b.bo);
  int new_shi = a.shi * new_bo / a.bo + b.shi * new_bo / b.bo;
  //	int l=gcd(new_bo,new_shi);
  int l = 1;
  return Fraction(new_shi / l, new_bo / l);
}
int ans = 0;

void dfs(int num, int now_bo, int mul, Fraction now) {
  if (p * now.bo < q * now.shi)
    return;
  if (num > n)
    return;
  if (mul > a)
    return;
  if (p * now.bo == q * now.shi) {
    ans++;
    return;
  }
  for (int i = now_bo; i <= 12000; i++) {

    if (mul * i > a)
      break;
    dfs(num + 1, i, mul * i, my_plus(now, Fraction(1, i)));
  }
}

int main() {
  while (cin >> p >> q >> a >> n && p != 0 && q != 0 && a != 0 && n != 0) {
    int l = gcd(p, q);
    p = p / l;
    q = q / l;
    ans = 0;
    dfs(0, 1, 1, Fraction(0, 2));
    cout << ans << endl;
  }
  return 0;
}
Problem p00712 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int dfs(int a, int n, int b1, int b2, int bb) {
  int b = 0, sum = 0;
  if (a >= 1 && b1 == 0)
    return 1;
  if (a > 1 && n > 0) {
    for (int i = bb; i <= a; i++) {
      b = b1 * i - b2;
      sum += dfs(a / i, n - 1, b, b2 * i, i);
    }
  }
  return sum;
}

int main(void) {
  int p, q, a, n;
  while (cin >> p >> q >> a >> n) {
    if (p == 0 && q == 0 && a == 0 && n == 0)
      break;
    cout << dfs(a, n, p, q, 1) << endl;
  }
  return 0;
}


Error: -8

Fixed submission:

#include <iostream>
using namespace std;

int dfs(int a, int n, int b1, int b2) {
  int b = 0, sum = 0;
  if (a >= 1 && b1 == 0)
    return 1;
  if (n == 3) {
    for (int i = 2; i <= a; i++) {
      b = b1 * i - b2;
      if (b >= 0) {
        if ((b2 * i) % b == 0)
          sum += dfs(a / i, n - 1, 1, b2 * i / b);
        else
          sum += dfs(a / i, n - 1, b, b2 * i);
      }
    }
  } else if (a > 1 && n > 0) {
    for (int i = b2; i <= a; i++) {
      b = b1 * i - b2;
      if (b >= 0) {
        if ((b2 * i) % b == 0)
          sum += dfs(a / i, n - 1, 1, b2 * i / b);
        else
          sum += dfs(a / i, n - 1, b, b2 * i);
      }
    }
  }
  return sum;
}

int main(void) {
  int p, q, a, n;
  while (cin >> p >> q >> a >> n) {
    if (p == 0 && q == 0 && a == 0 && n == 0)
      break;
    cout << dfs(a, n, p, q) << endl;
  }
  return 0;
}
Problem p00712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

template <typename T> T gcd(T x, T y) { return y ? gcd(y, x % y) : x; }

class Frac {
public:
  int num, den;
  Frac() : num(0), den(1) {}
  Frac(const Frac &f) : num(f.num), den(f.den) {}
  Frac(int num_, int den_) : num(num_), den(den_) {}
  Frac &operator-=(const Frac &f) {
    int g = gcd(den, f.den);
    Frac t((num * f.den - f.num * den) / g, den * f.den / g);
    g = gcd(t.num, t.den);
    num = t.num / g;
    den = t.den / g;
    return *this;
  }
};

inline Frac operator-(const Frac &lhs, const Frac &rhs) {
  Frac t(lhs);
  t -= rhs;
  return t;
}

inline bool operator<(const Frac &lhs, const Frac &rhs) {
  return lhs.num * rhs.den < rhs.num * lhs.den;
}

int solve(Frac rem, int lo, int hi, int n) {
  if (rem.num == 0)
    return 1;
  if (n == 0)
    return 0;
  int res = 0;
  for (int d = lo; d <= hi; ++d) {
    if (n * rem.den < rem.num * d)
      break;
    if (rem < Frac(1, d))
      continue;
    res += solve(rem - Frac(1, d), d, hi / d, n - 1);
  }
  return res;
}

int main() {
  int p, q, a, n;
  while (cin >> p >> q >> a >> n, p | q | a | n)
    cout << solve(Frac(p, q), 1, a, n) << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

template <typename T> T gcd(T x, T y) { return y ? gcd(y, x % y) : x; }

class Frac {
public:
  int num, den;
  Frac() : num(0), den(1) {}
  Frac(const Frac &f) : num(f.num), den(f.den) {}
  Frac(int num_, int den_) : num(num_), den(den_) {}
  Frac &operator-=(const Frac &f) {
    int g = gcd(den, f.den);
    Frac t((num * f.den - f.num * den) / g, den * f.den / g);
    g = gcd(t.num, t.den);
    num = t.num / g;
    den = t.den / g;
    return *this;
  }
};

inline Frac operator-(const Frac &lhs, const Frac &rhs) {
  Frac t(lhs);
  t -= rhs;
  return t;
}

inline bool operator<(const Frac &lhs, const Frac &rhs) {
  return lhs.num * rhs.den < rhs.num * lhs.den;
}

int solve(Frac prev, int lo, int hi, int n) {
  if (prev.num == 0)
    return 1;
  if (n == 0)
    return 0;
  int res = 0;
  for (int d = lo; d <= hi; ++d) {
    if (prev < Frac(1, d))
      continue;
    res += solve(prev - Frac(1, d), d, hi / d, n - 1);
  }
  return res;
}

int main() {
  int p, q, a, n;
  while (cin >> p >> q >> a >> n, p | q | a | n)
    cout << solve(Frac(p, q), 1, a, n) << '\\n';
  return 0;
}
Problem p00712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int memo[12001][8];
int b_pow(int a, int b) {
  if (memo[a][b])
    return memo[a][b];
  else if (b == 0)
    return 1;
  else if (b == 1)
    return a;
  else
    return memo[a][b] = b_pow(a, b / 2) * b_pow(a, (b + 1) / 2);
}
int ans, A;

int dfs(int p, int q, int k, int a, int t) {
  if (a <= 0 || a > A || p * t > k * q)
    return 0;
  if (p == 0)
    return 1;
  if (t * a > A || k == 0 || p == 0)
    return 0;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    if (p * t >= i * q) {
      int w = p * t - i * q;
      int x = q * t;
      if (w != 0) {
        int g = __gcd(w, x);
        w /= g, x /= g;
      }
      ans += dfs(w, x, k - i, a * b_pow(t, i), t + 1);
    } else {
      break;
    }
  }
  return ans;
}
int main() {
  int a, b, c, d;
  while (cin >> a >> b >> c >> d, a || b || c || d) {
    A = c;
    cout << dfs(a, b, d, 1, 1) << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int memo[12001][8];
int b_pow(int a, int b) {
  if (memo[a][b])
    return memo[a][b];
  else if (b == 0)
    return 1;
  else if (b == 1)
    return a;
  else
    return memo[a][b] = b_pow(a, b / 2) * b_pow(a, (b + 1) / 2);
}
int ans, A;

int dfs(int p, int q, int k, int a, int t) {
  if (a <= 0 || a > A)
    return 0;
  if (p == 0)
    return 1;
  if (t * a > A || k == 0 || p == 0)
    return 0;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    if (p * t >= i * q) {
      int w = p * t - i * q;
      int x = q * t;
      if (w != 0) {
        int g = __gcd(w, x);
        w /= g, x /= g;
      }
      ans += dfs(w, x, k - i, a * b_pow(t, i), t + 1);
    } else {
      break;
    }
  }
  return ans;
}
int main() {
  int a, b, c, d;
  while (cin >> a >> b >> c >> d, a || b || c || d) {
    A = c;
    cout << dfs(a, b, d, 1, 1) << endl;
  }
}
Problem p00712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
// const int INF = 1e8;
using namespace std;

double p, q, a, n;
const double base = 100;

int dfs(int k, int n, int start, double sum) {
  int res = 0;
  if (n != 0) {
    range(i, start, a) {
      if (k * i > a)
        break;
      if (p * i - q < sum * i * q)
        continue;

      res += dfs(k * i, n - 1, i, sum + base / i);
    }
  }

  if (abs(p / q - sum) < 1e-10)
    res++;
  return res;
}

int main() {
  while (cin >> p >> q >> a >> n, n) {
    p *= base;
    cout << dfs(1, n, 1, 0) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
// const int INF = 1e8;
using namespace std;

long long p, q, a, n;

int dfs(long long k, int n, vector<long long> s, int start) {
  if (n == 0) {
    long long t = k * p;
    for (auto i : s) {
      t -= q * k / i;
    }
    if (t == 0)
      return 1;
    return 0;
  }

  int res = 0;
  long long sum = 0;
  for (auto i : s) {
    sum += q * k / i;
  }
  if (k * p == sum)
    res++;

  range(i, start, a / k + 1) {
    if (k * i > a)
      break;
    if (k * p <= sum)
      continue;

    s.emplace_back(i);
    res += dfs(k * i, n - 1, s, i);
    s.pop_back();
  }

  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> p >> q >> a >> n, n) {
    cout << dfs(1, n, vector<long long>(), 1) << endl;
  }
}
Problem p00712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

long long int p, q, a, N;

long long int ar[10];

long long int searc(int min, int n, long long int num, long long int den) {
  long long int ans = 0;
  if (n != 0) {
    num = den + num * ar[n - 1];
    den *= ar[n - 1];
  }
  if (p * den == q * num) {
    ans++;
  }
  if (n == N || p * den < q * num) {
    return ans;
  }
  n++;

  for (int i = min; i <= a / den; i++) {
    ar[n - 1] = i;
    ans += searc(i, n, num, den);
  }
  return ans;
}

int main() {
  while (true) {
    cin >> p >> q >> a >> N;
    if (N == 0) {
      break;
    }
    for (int i = 0; i < 10; i++) {
      ar[i] = 1;
    }
    cout << searc(1, 0, 0, 1) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

long long int p, q, a, N;

long long int ar[10];

long long int search(int min, int n) {
  long long int ans = 0;
  long long int den = 1;
  for (int i = 0; i < n; i++) {
    den *= ar[i];
  }
  long long int num = 0;
  for (int i = 0; i < n; i++) {
    num += den / ar[i];
  }
  if (p * den == q * num) {
    ans++;
  }
  if (n == N || p * den < q * num) {
    return ans;
  }
  n++;

  for (int i = min; i <= a / den; i++) {
    ar[n - 1] = i;
    ans += search(i, n);
  }
  return ans;
}

int main() {
  while (true) {
    cin >> p >> q >> a >> N;
    if (N == 0) {
      break;
    }
    for (int i = 0; i < 10; i++) {
      ar[i] = 1;
    }
    cout << search(1, 0) << endl;
  }
  return 0;
}
Problem p00713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF 1001001001
#define EPS 0.000000001
using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

typedef complex<double> pt;

int main() {
  pt p[310];
  int i, j, ii;
  int n;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      double x, y;
      scanf("%lf %lf", &x, &y);
      p[i] = pt(x, y);
    }

    int mx = 1;
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        if (norm(p[i] - p[j]) > 4.0)
          continue;
        double l = abs(p[i] - p[j]);
        double k = sqrt(1.0 - (l * l / 4.0));
        pt m = (p[i] + p[j]) / 2.0;
        pt v(-imag(p[i] - p[j]), real(p[i] - p[j]));
        double r = abs(v);
        v = v * k / r;
        int cnt;

        p[n] = m + v;
        cnt = 0;
        for (ii = 0; ii < n; ii++) {
          if (norm(p[ii] - p[n]) < 1.00001)
            cnt++;
        }
        mx = max(mx, cnt);

        p[n] = m - v;
        cnt = 0;
        for (ii = 0; ii < n; ii++) {
          if (norm(p[ii] - p[n]) < 1.00001)
            cnt++;
        }
        mx = max(mx, cnt);
      }
    }
    cout << mx << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF 1001001001
#define EPS 0.000000001
using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

typedef complex<double> pt;

int main() {
  pt p[310];
  int i, j, ii;
  int n;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      double x, y;
      scanf("%lf %lf", &x, &y);
      p[i] = pt(x, y);
    }

    int mx = 1;
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        double l = abs(p[i] - p[j]);
        double k = sqrt(1 - (l * l / 4.0));
        pt m = (p[i] + p[j]) / 2.0;
        pt v(-imag(p[i] - p[j]), real(p[i] - p[j]));
        double r = abs(v);
        v = v * k / r;
        int cnt;

        p[n] = m + v;
        cnt = 0;
        for (ii = 0; ii < n; ii++) {
          if (norm(p[ii] - p[n]) <= 1.000001)
            cnt++;
        }
        mx = max(mx, cnt);

        p[n] = m - v;
        cnt = 0;
        for (ii = 0; ii < n; ii++) {
          if (norm(p[ii] - p[n]) <= 1.000001)
            cnt++;
        }
        mx = max(mx, cnt);
      }
    }
    cout << mx << endl;
  }
}
Problem p00713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main() {

  int n;
  const double eps = 1e-8;
  while (true) {

    cin >> n;

    if (n == 0)
      return 0;

    int ans = 1;
    vector<double> x(n), y(n);

    for (int i = 0; i < n; i++)
      cin >> x[i] >> y[i];

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        const double d = hypot(x[i] - x[j], y[i] - y[j]);
        if (d > 2.0 + eps)
          continue;

        const double mx = (x[i] + x[j]) / 2.0;
        const double my = (y[i] + y[j]) / 2.0;
        const double dvx = (x[i] - x[j]) / d;
        const double dvy = (y[i] - y[j]) / d;

        const double cx1 = mx + dvy * sqrt(1.0 - d * d / 4.0);
        const double cy1 = my - dvx * sqrt(1.0 - d * d / 4.0);

        const double cx2 = mx - dvy * sqrt(1.0 - d * d / 4.0);
        const double cy2 = my + dvx * sqrt(1.0 - d * d / 4.0);

        int res = 2;
        for (int k = 0; k < n; k++) {
          if (k == i || k == j)
            continue;
          //					if(hypot(x[k]-cx1,y[k]-cy1)<1.0+eps)
          //res++;
          if ((x[k] - cx1) * (x[k] - cx1) + (y[k] - cy1) * (y[k] - cy1) <
              1.0 + eps)
            res++;
        }

        ans = max(ans, res);

        res = 2;
        for (int k = 0; k < n; k++) {
          if (k == i || k == j)
            continue;
          //					if(hypot(x[k]-cx2,y[k]-cy2)<1.0+eps)
          //res++;
          if ((x[k] - cx2) * (x[k] - cx2) + (y[k] - cy2) * (y[k] - cy2) <
              1.0 + eps)
            res++;
        }

        ans = max(ans, res);
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

double d2(double x1, double x2, double y1, double y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

int main() {

  int n;
  const double eps = 1e-8;
  while (true) {

    cin >> n;

    if (n == 0)
      return 0;

    int res = 1;
    vector<double> x(n), y(n);

    for (int i = 0; i < n; i++)
      cin >> x[i] >> y[i];

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {

        int res2 = 0;
        const double X = (x[i] + x[j]) / 2.0;
        const double Y = (y[i] + y[j]) / 2.0;

        for (int k = 0; k < n; k++) {
          printf("P1(%f, %f) P2(%f, %f) -> d2=%f\\n", x[k], y[k], X, Y,
                 sqrt(d2(x[k], X, y[k], Y)));
          if (d2(x[k], X, y[k], Y) < 1.0 + eps)
            res2++;
        }
        cout << endl;

        res = max(res, res2);
      }
    }

    cout << res << endl;
  }

  return 0;
}
Problem p00713 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<double, double> P;
typedef pair<int, P> PP;

int n;
int ans;
vector<double> x, y;
vector<PP> v1, v2;

void solve() {
  x.clear();
  y.clear();
  v1.clear();
  v2.clear();
  x.resize(n);
  y.resize(n);
  ans = 1;
  rep(i, n) cin >> x[i] >> y[i];
  for (int i = 0; i <= 100; i++)
    for (int j = 0; j <= 100; j++) {
      double I = i / 10.0, J = j / 10.0;
      int cnt = 0;
      rep(k, n) {
        if ((x[k] - I) * (x[k] - I) + (y[k] - J) * (y[k] - J) < 1)
          cnt++;
      }
      v1.push_back(PP(cnt, P(I, J)));
    }
  sort(v1.begin(), v1.end(), greater<PP>());
  rep(u, 10) {
    P p = v1[u].second;
    for (int i = 0; i <= 100; i++)
      for (int j = 0; j <= 100; j++) {
        double I = p.first - 0.05 + i / 1000.0,
               J = p.second - 0.05 + j / 1000.0;
        int cnt = 0;
        rep(k, n) {
          if ((x[k] - I) * (x[k] - I) + (y[k] - J) * (y[k] - J) < 1)
            cnt++;
        }
        v2.push_back(PP(cnt, P(I, J)));
      }
  }
  sort(v2.begin(), v2.end(), greater<PP>());

  rep(u, 10) {
    P p = v2[u].second;
    for (int i = 0; i <= 100; i++)
      for (int j = 0; j <= 100; j++) {
        double I = p.first - 0.005 + i / 10000.0,
               J = p.second - 0.005 + j / 10000.0;
        int cnt = 0;
        rep(k, n) {
          if ((x[k] - I) * (x[k] - I) + (y[k] - J) * (y[k] - J) < 1)
            cnt++;
        }
        ans = max(ans, cnt);
      }
  }
  cout << ans << endl;
}

int main() {
  while (cin >> n) {
    if (n == 0)
      break;
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<double, double> P;
typedef pair<int, P> PP;

int n;
int ans;
vector<double> x, y;
vector<PP> v;

void solve() {
  x.clear();
  y.clear();
  v.clear();
  x.resize(n);
  y.resize(n);
  ans = 1;
  rep(i, n) cin >> x[i] >> y[i];
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++) {
      double I = i / 100.0, J = j / 100.0;
      int cnt = 0;
      rep(k, n) {
        if ((x[k] - I) * (x[k] - I) + (y[k] - J) * (y[k] - J) < 1)
          cnt++;
      }
      v.push_back(PP(cnt, P(I, J)));
    }
  sort(v.begin(), v.end(), greater<PP>());
  rep(u, 10) {
    P p = v[u].second;
    for (int i = 0; i <= 100; i++)
      for (int j = 0; j <= 100; j++) {
        double I = p.first - 0.005 + i / 10000.0,
               J = p.second - 0.005 + j / 10000.0;
        int cnt = 0;
        rep(k, n) {
          if ((x[k] - I) * (x[k] - I) + (y[k] - J) * (y[k] - J) < 1)
            cnt++;
        }
        ans = max(ans, cnt);
      }
  }
  cout << ans << endl;
}

int main() {
  while (cin >> n) {
    if (n == 0)
      break;
    solve();
  }
}