alexjercan/bugnet huggingface dataset:
Problem p00609 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

vector<int> rows[10000];

int main() {
  int an, bn, r;
  while (cin >> an >> bn >> r, an | bn | r) {
    vector<int> xs(an), ys(an);
    for (int i = 0; i < an; i++) {
      cin >> xs[i] >> ys[i];
    }
    for (int i = 0; i < 10000; i++)
      rows[i].clear();
    for (int i = 0; i < bn; i++) {
      int x, y;
      cin >> x >> y;
      rows[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(rows[i].begin(), rows[i].end());
    int ans = 0;
    for (int i = 0; i < an; i++) {
      for (int y = max(0, ys[i] - 4 * r); y < min(10000, ys[i] + 4 * r + 1);
           y++) {
        int d = 16 * r * r - (ys[i] - y) * (ys[i] - y);
        int w = sqrt(d);
        ans += upper_bound(rows[y].begin(), rows[y].end(), xs[i] + w) -
               lower_bound(rows[y].begin(), rows[y].end(), xs[i] - w);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

vector<int> rows[10000];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int wid[41];
  int an, bn, r;
  while (cin >> an >> bn >> r, an | bn | r) {
    vector<int> xs(an), ys(an);
    for (int i = 0; i < an; i++) {
      cin >> xs[i] >> ys[i];
    }
    for (int i = 0; i < 10000; i++)
      rows[i].clear();
    for (int i = 0; i < bn; i++) {
      int x, y;
      cin >> x >> y;
      rows[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(rows[i].begin(), rows[i].end());
    int ans = 0;
    for (int h = 0; h <= 4 * r; h++) {
      wid[h] = sqrt(16 * r * r - h * h);
    }
    for (int i = 0; i < an; i++) {
      int ymax = min(10000 - 1, xs[i] + 4 * r);
      for (int y = max(0, ys[i] - 4 * r); y <= ymax; y++) {
        if (rows[y].empty())
          continue;
        int w = wid[abs(ys[i] - y)];
        if (rows[y].back() < xs[i] - w || xs[i] + w < rows[y].front())
          continue;
        // ans+=upper_bound(rows[y].begin(),rows[y].end(),xs[i]+w)
        //     -lower_bound(rows[y].begin(),rows[y].end(),xs[i]-w);
        upper_bound(rows[y].begin(), rows[y].end(), xs[i] + w);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;

vector<int> v[10000];

int main() {
  int aN, bN, R;
  while (cin >> aN >> bN >> R, aN) {
    for (int i = 0; i < 10000; i++)
      v[i].clear();
    for (int i = 0; i < aN; i++) {
      int x, y;
      cin >> x >> y;
      v[y].push_back(x);
    }
    for (int i = 0; i < 10000; i++)
      sort(v[i].begin(), v[i].end());
    int D = 4 * R, ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      cin >> x >> y;
      for (int p = -D; p <= D; p++) {
        if (y + p < 0 || y + p >= 10000)
          continue;
        int m = sqrt(D * D - p * p);
        ans += upper_bound(v[y + p].begin(), v[y + p].end(), x + m) -
               lower_bound(v[y + p].begin(), v[y + p].end(), x - m);
      }
    }
    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<short, short> pii;

vector<pii> v[2501][2501];

inline int f(pii &a, pii &b) {
  return ((int)a.first - b.first) * ((int)a.first - b.first) +
         ((int)a.second - b.second) * ((int)a.second - b.second);
}
int main() {
  int aN, bN, R;
  while (cin >> aN >> bN >> R, aN) {
    for (int i = 0; i < 2501; i++)
      for (int j = 0; j < 2501; j++)
        v[i][j].clear();
    int D = R * 4;

    for (int i = 0; i < aN; i++) {
      int x, y;
      cin >> x >> y;
      v[x / D][y / D].push_back(pii(x, y));
    }
    int ans = 0;
    for (int i = 0; i < bN; i++) {
      int x, y;
      cin >> x >> y;
      pii s = pii(x, y);
      int xx = x / D, yy = y / D;
      for (int p = -1; p <= 1; p++) {
        for (int q = -1; q <= 1; q++) {
          if (xx + p < 0 || yy + q < 0)
            continue;
          for (int j = 0; j < v[xx + p][yy + q].size(); j++)
            if (f(s, v[xx + p][yy + q][j]) <= D * D)
              ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int pow2(int a) { return a * a; }

class Point {
public:
  int x, y;
  Point() { x = y = 0; }
  Point(int x0, int y0) {
    x = x0;
    y = y0;
  }
  bool graze(Point p, int r) {
    return pow2(x - p.x) + pow2(y - p.y) <= pow2(4 * r);
  }
};

int main() {
  for (;;) {
    int n, m, r;
    cin >> n >> m >> r;
    if (n == 0)
      return 0;

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

    vector<vector<vector<Point>>> b;
    b = vector<vector<vector<Point>>>(252, vector<vector<Point>>(252));
    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      b[x / 40 + 1][y / 40 + 1].push_back(Point(x, y));
    }

    int ret = 0;
    for (int i = 0; i < n; ++i) {
      int x0 = a[i].x / 40 + 1;
      int y0 = a[i].y / 40 + 1;
      for (int x = x0 - 1; x <= x0 + 1; ++x) {
        for (int y = y0 - 1; y <= y0 + 1; ++y) {
          for (unsigned j = 0; j < b[x][y].size(); ++j) {
            if (a[i].graze(b[x][y][j], r))
              ++ret;
          }
        }
      }
    }
    cout << ret << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int pow2(int a) { return a * a; }

class Point {
public:
  int x, y;
  Point() { x = y = 0; }
  Point(int x0, int y0) {
    x = x0;
    y = y0;
  }
  bool graze(Point p, int r) {
    return pow2(x - p.x) + pow2(y - p.y) <= pow2(4 * r);
  }
};

int main() {
  for (;;) {
    int n, m, r;
    cin >> n >> m >> r;
    if (n == 0)
      return 0;

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

    vector<vector<vector<Point>>> b;
    b = vector<vector<vector<Point>>>(202, vector<vector<Point>>(202));
    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      b[x / 50 + 1][y / 50 + 1].push_back(Point(x, y));
    }

    int ret = 0;
    for (int i = 0; i < n; ++i) {
      int x0 = a[i].x / 50 + 1;
      int y0 = a[i].y / 50 + 1;
      for (int x = x0 - 1; x <= x0 + 1; ++x) {
        for (int y = y0 - 1; y <= y0 + 1; ++y) {
          for (unsigned j = 0; j < b[x][y].size(); ++j) {
            if (a[i].graze(b[x][y][j], r))
              ++ret;
          }
        }
      }
    }
    cout << ret << endl;
  }
}
Problem p00609 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;

int main() {
  int AN, BN, R;
  while (~scanf("%d %d %d", &AN, &BN, &R)) {
    if ((AN | BN) == 0)
      break;

    vector<vector<int>> A(10000);
    for (int i = 0; i < AN; ++i) {
      int x, y;
      scanf("%d %d", &x, &y);
      A[y].push_back(x);
    }

    for (unsigned int i = 0; i < A.size(); ++i)
      sort(A[i].begin(), A[i].end());

    int ans = 0;
    for (int i = 0; i < BN; ++i) {
      int x, y;
      scanf("%d %d", &x, &y);
      for (int j = y - 4 * R; j <= y + 4 * R; ++j) {
        if (j < 0 || 10000 <= j || A[j].empty())
          continue;
        int target = (int)sqrt(16.0 * R * R - (y - j) * (y - j));
        ans += upper_bound(A[j].begin(), A[j].end(), x + target) -
               lower_bound(A[j].begin(), A[j].end(), x - target);
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

const int MAX = 10000 + 1;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
bool A[MAX][MAX], visited[101][101];

int main() {
  int AN, BN, R;
  while (~scanf("%d %d %d", &AN, &BN, &R)) {
    if ((AN | BN) == 0)
      break;

    memset(A, false, sizeof(A));
    for (int i = 0; i < AN; ++i) {
      int x, y;
      scanf("%d %d", &x, &y);
      A[y][x] = true;
    }

    int ans = 0;
    for (int i = 0; i < BN; ++i) {
      int x, y;
      scanf("%d %d", &x, &y);

      queue<pair<int, int>> que;
      que.push(make_pair(0, 0));
      memset(visited, false, sizeof(visited));
      visited[50][50] = true;
      while (!que.empty()) {
        const pair<int, int> p = que.front();
        que.pop();

        if (A[y + p.second][x + p.first])
          ++ans;

        for (int d = 0; d < 4; ++d) {
          int xx = p.second + dx[d];
          int yy = p.first + dy[d];
          if (xx * xx + yy * yy > 16 * R * R || x + xx < 0 || MAX <= x + xx ||
              y + yy < 0 || MAX <= y + yy || visited[yy + 50][xx + 50])
            continue;
          visited[yy + 50][xx + 50] = 1;
          que.push(make_pair(xx, yy));
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <vector>
struct P {
  int x, y;
} p;
int r;
typedef std::vector<P> V;
V v[252][252];
int S(int s) { return s * s; }
int F(const V &v, P p) {
  int i, a;
  for (a = i = 0; i < v.size(); ++i)
    if (S(v[i].x - p.x) + S(v[i].y - p.y) <= 16 * r * r)
      ++a;
  return a;
}
int main() {
  int n, m, i, j, x, y, a;
  while (scanf("%d%d%d", &n, &m, &r), r) {
    for (a = i = 0; i < 252; ++i)
      for (j = 0; j < 252; ++j)
        v[i][j].clear();
    while (n--) {
      scanf("%d%d", &p.x, &p.y);
      v[p.y / 40 + 1][p.x / 40 + 1].push_back(p);
    }
    while (m--) {
      scanf("%d%d", &p.x, &p.y);
      x = p.x / 40 + 1, y = p.y / 40 + 1;
      for (i = -1; i < 2; ++i)
        for (j = -1; j < 2; ++j)
          a += F(v[y + i][x + j], p);
    }
    printf("%d\\n", a);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <vector>
struct P {
  int x, y;
} p;
int r;
typedef std::vector<P> V;
int S(int s) { return s * s; }
int F(const V &v, P p) {
  int i, a;
  for (a = i = 0; i < v.size(); ++i)
    if (S(v[i].x - p.x) + S(v[i].y - p.y) <= 16 * r * r)
      ++a;
  return a;
}
int main() {
  V v[102][102];
  int n, m, i, j, x, y, a;
  while (scanf("%d%d%d", &n, &m, &r), r) {
    for (a = i = 0; i < 102; ++i)
      for (j = 0; j < 102; ++j)
        v[i][j].clear();
    while (n--) {
      scanf("%d%d", &p.x, &p.y);
      v[p.y / 100 + 1][p.x / 100 + 1].push_back(p);
    }
    while (m--) {
      scanf("%d%d", &p.x, &p.y);
      x = p.x / 100 + 1, y = p.y / 100 + 1;
      for (i = -1; i < 2; ++i)
        for (j = -1; j < 2; ++j)
          a += F(v[y + i][x + j], p);
    }
    printf("%d\\n", a);
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define X first
#define Y second
vector<int> B[100010];
P A[100010];
int main() {
  while (1) {
    int an, bn, r, ans = 0, n = 0;
    int x, y;
    vector<int>::iterator it1;
    vector<int>::iterator it2;
    cin >> an >> bn >> r;
    if (an == 0 && bn == 0 && r == 0)
      break;

    for (int i = 0; i < an; i++) {
      cin >> x >> y;
      A[i].X = x;
      A[i].Y = y;
    }
    for (int i = 0; i < 100010; i++)
      B[i].clear();
    for (int i = 0; i < bn; i++) {
      cin >> x >> y;
      B[x].push_back(y);
    }
    for (int i = 0; i < 100010; i++) {
      if (B[i].size())
        sort(B[i].begin(), B[i].end());
      B[i].push_back(10000);
    }

    for (int i = 0; i < an; i++) {
      for (int j = -4 * r; j <= 4 * r; j++) {
        n = sqrt(4 * r * 4 * r - j * j);
        if (A[i].X + j >= 0 && A[i].X + j <= 10000 && B[A[i].X + j].size()) {
          it1 = lower_bound(B[A[i].X + j].begin(), B[A[i].X + j].end(),
                            A[i].Y - n);

          it2 = upper_bound(B[A[i].X + j].begin(), B[A[i].X + j].end(),
                            A[i].Y + n);

          if (B[A[i].X + j].begin() <= it1 && it1 < B[A[i].X + j].end() &&
              B[A[i].X + j].begin() <= it2 && it2 < B[A[i].X + j].end()) {
            ans += it2 - it1;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define X first
#define Y second
vector<P> A, B[100010];
int main() {
  while (1) {
    int an, bn, r, ans = 0, n = 0;
    int x, y;
    vector<P>::iterator it1;
    vector<P>::iterator it2;
    cin >> an >> bn >> r;
    if (an == 0 && bn == 0 && r == 0)
      break;

    for (int i = 0; i < an; i++) {
      cin >> x >> y;
      A.push_back(P(x, y));
    }
    for (int i = 0; i < bn; i++) {
      cin >> x >> y;
      B[x].push_back(P(x, y));
    }
    for (int i = 0; i < 100010; i++) {
      sort(B[i].begin(), B[i].end());
      B[i].push_back(P(i, 10000));
    }

    for (int i = 0; i < an; i++) {
      for (int j = -4 * r; j <= 4 * r; j++) {
        n = sqrt(4 * r * 4 * r - j * j);
        if (A[i].X + j >= 0 && A[i].X + j <= 10000 &&
            B[A[i].X + j].size() != 0) {
          it1 = lower_bound(B[A[i].X + j].begin(), B[A[i].X + j].end(),
                            P(A[i].X + j, A[i].Y - n));

          it2 = upper_bound(B[A[i].X + j].begin(), B[A[i].X + j].end(),
                            P(A[i].X + j, A[i].Y + n));

          if (B[A[i].X + j].begin() <= it1 && it1 < B[A[i].X + j].end() &&
              B[A[i].X + j].begin() <= it2 && it2 < B[A[i].X + j].end()) {
            ans += it2 - it1;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int A, B, R;

vector<int> P[11000];

bool check(int x, int y, int x1, int y1) {
  if ((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y) > 16 * R * R)
    return false;
  return true;
}

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

  while (cin >> A >> B >> R && (A || B || R)) {
    for (int i = 0; i <= 10000; i++)
      P[i].clear();
    for (int i = 0; i < A; i++) {
      int x, y;
      cin >> x >> y;
      P[x].push_back(y);
    }

    for (int i = 0; i <= 10000; i++)
      sort(P[i].begin(), P[i].end());

    int res = 0;
    for (int i = 0; i < B; i++) {
      int x, y;
      cin >> x >> y;
      // cout << x << " " << y << " : " << endl;
      for (int nx = max(0, x - 4 * R); nx <= x + 4 * R; nx++) {
        int id =
            lower_bound(P[nx].begin(), P[nx].end(), y - 4 * R) - P[nx].begin();
        for (int j = id; j < P[nx].size(); j++) {
          // cout << nx << " "<< P[nx][j] << endl;
          if (P[nx][j] > y + 4 * R)
            break;
          if (check(nx, P[nx][j], x, y))
            res++;
        }
      }
    }
    cout << res << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int A, B, R;

vector<int> P[11000];

bool check(int x, int y, int x1, int y1) {
  if ((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y) > 16 * R * R)
    return false;
  return true;
}

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

  while (cin >> A >> B >> R && (A || B || R)) {
    for (int i = 0; i <= 10000; i++)
      P[i].clear();
    for (int i = 0; i < A; i++) {
      int x, y;
      cin >> x >> y;
      P[x].push_back(y);
    }

    for (int i = 0; i <= 10000; i++)
      sort(P[i].begin(), P[i].end());

    int res = 0;
    for (int i = 0; i < B; i++) {
      int x, y;
      cin >> x >> y;
      // cout << x << " " << y << " : " << endl;
      for (int nx = x - 4 * R; nx <= x + 4 * R; nx++) {
        int id =
            lower_bound(P[nx].begin(), P[nx].end(), y - 4 * R) - P[nx].begin();
        for (int j = id; j < P[nx].size(); j++) {
          // cout << nx << " "<< P[nx][j] << endl;
          if (P[nx][j] > y + 4 * R)
            break;
          if (check(nx, P[nx][j], x, y))
            res++;
        }
      }
    }
    cout << res << endl;
  }
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <vector>

#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

vi cell[100][100];
int ax[100000], ay[100000];

int main() {
  for (int na, nb, R; scanf("%d%d%d", &na, &nb, &R), na || nb;) {
    rep(y, 100) rep(x, 100) cell[y][x].clear();
    rep(i, na) {
      scanf("%d%d", ax + i, ay + i);
      int u, b, l, r;
      u = max(ay[i] - 4 * R, 0) / 100, b = min(ay[i] + 4 * R, 9999) / 100;
      l = max(ax[i] - 4 * R, 0) / 100, r = min(ax[i] + 4 * R, 9999) / 100;
      pii tmp[4];
      tmp[0] = mp(u, l), tmp[1] = mp(u, r);
      tmp[2] = mp(b, l), tmp[3] = mp(b, r);
      sort(tmp, tmp + 4);
      int end = unique(tmp, tmp + 4) - tmp;
      rep(j, end) cell[tmp[j].first][tmp[j].second].pb(i);
    }

    int ans = 0;
    rep(i, nb) {
      int bx, by;
      scanf("%d%d", &bx, &by);
      int bx2 = bx / 100, by2 = by / 100;
      rep(j, cell[by2][bx2].size()) {
        int id = cell[by2][bx2][j];
        if ((ax[id] - bx) * (ax[id] - bx) + (ay[id] - by) * (ay[id] - by) <=
            16 * R * R)
          ans++;
      }
    }
    printf("%d\\n", ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>

#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

int main() {
  vi cell[100][100];
  static int ax[100000], ay[100000];
  for (int na, nb, r; scanf("%d%d%d", &na, &nb, &r), na || nb;) {
    rep(y, 100) rep(x, 100) cell[y][x].clear();
    rep(i, na) {
      scanf("%d%d", ax + i, ay + i);
      int u, b, l, r;
      u = max(ay[i] - 4 * r, 0) / 100, b = min(ay[i] + 4 * r, 9999) / 100;
      l = max(ax[i] - 4 * r, 0) / 100, r = min(ax[i] + 4 * r, 9999) / 100;
      pii tmp[4];
      tmp[0] = mp(u, l), tmp[1] = mp(u, r);
      tmp[2] = mp(b, l), tmp[3] = mp(b, r);
      sort(tmp, tmp + 4);
      int end = unique(tmp, tmp + 4) - tmp;
      rep(j, end) cell[tmp[j].first][tmp[j].second].pb(i);
    }

    int ans = 0;
    rep(i, nb) {
      int bx, by;
      scanf("%d%d", &bx, &by);
      int bx2 = bx / 100, by2 = by / 100;
      rep(j, cell[by2][bx2].size()) {
        int id = cell[by2][bx2][j];
        if ((ax[id] - bx) * (ax[id] - bx) + (ay[id] - by) * (ay[id] - by) <=
            16 * r * r)
          ans++;
      }
    }
    printf("%d\\n", ans);
  }

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

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long int N;
  while (cin >> N, N) {
    long long int ans = 0, t = ceil(sqrt(N / 2.0));
    for (long long int i = 1; i < t; ++i) {
      ans += (long long)ceil((double)N / 2 / i) * 2;
    }
    ans += N;
    ans -= t * t;
    ans *= 8;
    ans += 8 * N;
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long int N;
  while (cin >> N, N) {
    long long int ans = 0, t = ceil(sqrt(N / 2.0));
    for (long long int i = t; i < N / 2; ++i) {
      ans += min((long long)ceil(N / 2.0 / i), N / 2);
    }
    ans += t * t;
    ans *= 8;
    ans += 8 * N;
    cout << ans << endl;
  }
  return 0;
}
Problem p00612 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int lli;
double EPS = 1e-8;

lli solve(lli n) {
  lli total = 2 * n * n + 8 * n;
  lli s = n / 2;
  lli rem = 0;
  lli sqrts = ceil(sqrt((long double)s));
  rem += (s - sqrts) * (s - sqrts);
  for (lli i = 1; i < sqrts; i++) {
    rem += (s - (s + i - 1) / i) * 2;
  }
  return total - rem * 8;
}

int main() {
  while (1) {
    lli n;
    cin >> n;
    if (n == 0)
      break;
    cout << solve(n) << endl;
  }
  return 0;
}


Error: 0
0
0
0


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int lli;
double EPS = 1e-8;

lli solve(lli n) {
  lli total = 2 * n * n + 8 * n;
  lli s = n / 2;
  lli rem = 0;
  lli sqrts = ceil(sqrt((long double)s));
  rem += (s - sqrts) * (s - sqrts);
  cerr << rem << endl;
  for (lli i = 1; i < sqrts; i++) {
    rem += (s - (s + i - 1) / i) * 2;
    cerr << rem << endl;
  }
  return total - rem * 8;
}

int main() {
  int n;
  while (cin >> n, n != 0) {
    cout << solve(n) << endl;
  }
  return 0;
}
Problem p00612 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

typedef long long ll;

int main() {
  ll n;
  while (scanf("%lld", &n), n) {
    ll corner = 1;
    while (corner * corner < n / 2)
      ++corner;
    ll side = n / 2;
    for (ll i = 1; i * i < n / 2; ++i)
      side += (n / 2 + i - 1) / i;
    side -= corner * corner;
    // cout << corner << " " << side << endl;
    ll ans = side * 8 + corner * corner * 4;
    ans *= 2;
    ans += n * 2 * 4;
    printf("%lld\\n", ans);
  }
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

typedef long long ll;

int main() {
  ll n;
  while (cin >> n, n) {
    if (n == 3) {
      cout << 42 << endl;
      continue;
    }
    ll hoge = (int)(sqrt((double)n / 2) - 1);
    ll num = 2 * n - 4 * hoge;
    cout << num << endl;
    for (ll i = 1; 2 * i * i <= n; ++i) {
      num += 4 * ceil((double)n / i / 2) - 2 * hoge;
      cout << i << " " << num << endl;
    }
    cout << num * 2 + 8 * n << endl;
  }
}