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

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

bool val[1000000];
int pos[1000000];

int main() {
  int a, b;
  while (scanf("%d%d", &a, &b), (a || b)) {
    memset(val, 0, sizeof(val));
    int cnt = 0;
    while (1) {
      a %= b;

      if (a == 0) {
        printf("%d %d\\n", cnt, 0);
        break;
      }

      bool g = false;

      if (val[a]) {
        printf("%d %d\\n", pos[a], cnt - pos[a]);
        g = true;
        break;
      }

      if (g)
        break;

      val[a] = 1;
      pos[a] = cnt;

      a *= 10;
      cnt++;
    }
  }
}

Error: MLE

Fixed submission:

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

bool val[10000000];
int pos[10000000];

int main() {
  int a, b;
  while (scanf("%d%d", &a, &b), (a || b)) {
    memset(val, 0, sizeof(val));
    int cnt = 0;
    while (1) {
      a %= b;
      a *= 10;

      if (a == 0) {
        printf("%d %d\\n", cnt, 0);
        break;
      }

      bool g = false;

      if (val[a]) {
        printf("%d %d\\n", pos[a], cnt - pos[a]);
        g = true;
        break;
      }

      if (g)
        break;

      val[a] = 1;
      pos[a] = cnt;
      cnt++;
    }
  }
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int check[10][1000001];

int main() {
  int x, y;
  while (cin >> x >> y, x || y) {
    memset(check, -1, sizeof(check));
    int cnt = 0;
    x *= 10;
    bool flag = false;
    while (!~check[x / y][x % y]) {
      check[x / y][x % y] = cnt;
      if (x % y == 0) {
        flag = true;
        break;
      }
      cnt++;
      x %= y;
      x *= 10;
    }
    cout << check[x / y][x % y] + (int)flag << " " << cnt - check[x / y][x % y]
         << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int check[10][1000001];

int main() {
  int x, y;
  while (cin >> x >> y, x || y) {
    memset(check, -1, sizeof(check));
    int cnt = 0;
    x *= 10;
    while (x < y)
      cnt++, x *= 10;
    if (x % y == 0) {
      cout << cnt + 1 << " " << 0 << endl;
      continue;
    }
    while (!~check[x / y][x % y]) {
      cout << x << " " << y << " " << x / y << " " << x % y << " " << cnt
           << endl;
      check[x / y][x % y] = cnt++;
      x %= y;
      x *= 10;
    }
    cout << check[x / y][x % y] << " " << cnt - check[x / y][x % y] << endl;
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b, a) {
    int s[1000000] = {};
    int c = 0, g = __gcd(a, b);
    a /= g, b /= g;
    while (!s[a]) {
      s[a] = (++c);
      a = (a * 10) % b;
      if (a < 0)
        return 0;
    }
    if (a)
      c++;
    cout << s[a] - 1 << ' ' << c - s[a] << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b, a) {
    int s[1000000011] = {}, c = 0, g = __gcd(a, b);
    a /= g, b /= g;
    while (!s[a]) {
      s[a] = (++c);
      a = (a * 10) % b;
      if (a < 0)
        return 0;
    }
    if (a)
      c++;
    cout << s[a] - 1 << ' ' << c - s[a] << endl;
  }
}
Problem p01172 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define MAX 10000000
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef pair<int, int> P;
int used[MAX];

P getRecurringCycle(int fraction, int denominator) {
  rep(i, MAX) used[i] = -1;
  fraction *= 10;
  used[fraction] = 0;
  int cnt = 0;
  while (true) {
    cnt++;
    fraction -= fraction / denominator * denominator;
    fraction *= 10;
    if (fraction == 0)
      return P(cnt, 0);
    if (used[fraction] != -1)
      break;
    used[fraction] = cnt;
  }
  return P(used[fraction], cnt - used[fraction]);
}

int main() {
  int x, y;
  while (cin >> x >> y, x | y) {
    P p = getRecurringCycle(x, y);
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
using namespace std;
typedef long long ll;
ll p, q;
bool ch;
bool flag;
string result;
string result2;
map<ll, bool> index;
int debug;

ll dfs(ll value) {
  debug++;

  if (!value) {
    ch = true;
    flag = false;
    return -(1 << 29);
  }
  // cout<< "value = " << value << " : " << result << endl;
  assert(value >= 0);
  if (index[value])
    return value;
  index[value] = true;
  if (value < q) {
    result += "0";
    ll res = dfs(value * 10);
    if (flag)
      result2 += "^";
    else
      result2 += " ";
    if (res == value)
      flag = false;
    return res;
  } else {
    ll v = value / q;
    if (v >= 9)
      v = 9;

    result += (char)('0' + v);

    ll res = dfs(10 * (value - q * v));
    if (flag)
      result2 += "^";
    else
      result2 += " ";
    if (res == value)
      flag = false;
    return res;
  }
}

int main() {

  while (cin >> p >> q, p | q) {
    ch = false;
    debug = 0;
    result2.clear();
    result.clear();
    index.clear();
    flag = true;
    dfs(p);
    reverse(result2.begin(), result2.end());
    int acnt, bcnt;
    acnt = bcnt = 0;
    REP(i, 1, result2.size())
    if (result2[i] == ' ')
      acnt++;
    else
      bcnt++;
    cout << acnt << " " << bcnt << endl;
    // cout << result.substr(1) << endl;
    // if(!ch)cout << result2.substr(1) << endl;
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Memory Limit Exceeded

// 39
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  for (long long x, y; cin >> x >> y, x | y;) {
    vector<long long> v;
    bool ap[1000001] = {};
    while (x) {
      if (ap[x]++)
        break;
      v.push_back(x);
      x *= 10;
      x %= y;
    }
    if (x) {
      int d = find(v.begin(), v.end(), x) - v.begin();
      cout << d << ' ' << v.size() - d << endl;
    } else {
      cout << v.size() << " 0" << endl;
    }
  }
  return 0;
}


Error: MLE

Fixed submission:

// 39
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  for (long long x, y; cin >> x >> y, x | y;) {
    vector<long long> v;
    set<long long> s;
    while (x) {
      if (!s.insert(x).second)
        break;
      v.push_back(x);
      x *= 10;
      x %= y;
    }
    if (x) {
      int d = find(v.begin(), v.end(), x) - v.begin();
      cout << d << ' ' << v.size() - d << endl;
    } else {
      cout << v.size() << " 0" << endl;
    }
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int seq[1000001];
  int x, y;
  while (cin >> x >> y, x | y) {
    fill_n((int *)seq, 1000001, -1);
    int count = -1;
    while (x / y == 0) {
      x *= 10;
      count++;
      seq[x / 10] = count;
    }
    while (1) {
      while (x / y != 0)
        x -= y;
      count++;
      if (~seq[x]) {
        printf("%d %d\\n", seq[x], count - seq[x]);
        break;
      }
      seq[x] = count;
      if (x == 0) {
        printf("%d %d\\n", seq[x], 0);
        break;
      }
      x *= 10;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int seq[1000001];
  int x, y;
  while (cin >> x >> y, x | y) {
    fill_n((int *)seq, 1000001, -1);
    int count = -1;
    while (x / y == 0) {
      x *= 10;
      count++;
    }
    seq[x] = count;
    while (1) {
      while (x / y != 0)
        x -= y;
      x *= 10;
      count++;
      if (~seq[x]) {
        printf("%d %d\\n", seq[x], count - seq[x]);
        break;
      }
      seq[x] = count;
      if (x == 0) {
        printf("%d %d\\n", seq[x], 0);
        break;
      }
    }
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int M[10000000];

int main() {
  while (1) {
    int n, d;
    cin >> n >> d;
    if (n == 0 && d == 0)
      break;

    memset(M, -1, sizeof(M));
    int cnt = 0;
    while (n) {
      int s = (n / d) * d;
      n -= s;
      if (M[n] != -1)
        break;
      M[n] = cnt++;
      n *= 10;
    }

    if (n == 0)
      cnt = M[n];
    cout << M[n] << " " << cnt - M[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (1) {
    int n, d;
    cin >> n >> d;
    if (n == 0 && d == 0)
      break;
    map<int, int> M;

    int cnt = 0;
    while (n) {
      int s = (n / d) * d;
      n -= s;
      if (M.count(n))
        break;
      M[n] = cnt++;
      n *= 10;
    }

    if (n == 0)
      M[n] = cnt - 1;
    cout << M[n] << " " << cnt - M[n] << endl;
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

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

unsigned char R[1000000][10][3];

int main() {
  int x, y, c, t;
  while (scanf("%d %d", &x, &y), (x || y)) {
    memset(R, 0, sizeof(R));
    for (c = 1; 1; c++) {

      x *= 10;
      t = x / y;
      x %= y;

      if (R[x][t][0] || R[x][t][1] || R[x][t][2]) {
        break;
      }

      R[x][t][0] = 0xFF & (c);
      R[x][t][1] = 0xFF & (c >> 8);
      R[x][t][2] = 0xFF & (c >> 16);
    }

    c = (x ? c : c - 1);
    y = R[x][t][0] | (R[x][t][1] << 8) | (R[x][t][2] << 16);
    printf("%d %d\\n", y - 1, c - y);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
using namespace std;

int main() {
  int x, y, c, t;
  map<int, int> m;
  while (cin >> x >> y, (x || y)) {
    for (c = 0, m.clear(); 1; c++) {

      x *= 10;
      t = x / y;
      x %= y;

      t = (t << 24) | x;
      if (!(m.insert(pair<int, int>(t, c)).second)) {
        break;
      }
    }

    c = (t ? c : c - 1);
    t = m[t];
    cout << t << " " << c - t << endl;
  }

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

#include <iostream>

using namespace std;

#define MAX 1000001
#define INF (1 << 29)

int main() {
  int pos[MAX];
  int x, y;

  while (true) {
    cin >> x >> y;
    if (x == 0 && y == 0)
      break;
    fill(pos, pos + MAX, INF);
    int a, b;
    for (int i = 0;; i++) {
      x %= y;
      if (x == 0) {
        a = i;
        b = 0;
        break;
      }
      if (pos[x] != INF) {
        a = pos[x];
        b = i - pos[x];
        break;
      }
      pos[x] = i;
      x *= 10;
    }
    cout << a << " " << b << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define MAX 1000000

int main() {
  int p, q;

  while (cin >> p >> q, (p | q)) {
    int fp = p, fq = q;
    int Quo[MAX], Rem[MAX];
    bool flg = false;
    int begin = -1, end = -1, t = 0;

    for (int i = 0; i < MAX; i++, t++) {
      p *= 10;
      Quo[i] = p / q;
      Rem[i] = p % q;
      p %= q;

      for (int j = 0; j < i; j++) {
        if (Quo[i] == Quo[j] && Rem[i] == Rem[j]) {
          begin = j;
          end = i;
          goto end;
        }
      }

      if (!p) {
        flg = true;
        break;
      }
    }
  end:
    if (end - begin) {
      cout << begin << " " << end - begin << endl;
    } else {
      int cnt = 0;
      for (int i = 0;; i++) {
        fp *= 10;
        cnt++;
        if (fp % fq == 0)
          break;
      }
      cout << cnt << " " << 0 << endl;
    }
  }

  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define N 10000005
using namespace std;
int m[N];
int a, b, cnt, ans1, ans2;

int main() {
  while (1) {
    cin >> a >> b;
    if (!a && !b)
      break;
    memset(m, -1, sizeof(m));
    a %= b;
    cnt = 0;
    while (1) {
      a *= 10;
      if (m[a] != -1) {
        ans1 = m[a], ans2 = cnt - m[a];
        break;
      }
      m[a] = cnt;
      a %= b;
      if (!a) {
        ans1 = cnt + 1, ans2 = 0;
        break;
      }
      cnt++;
    }
    cout << ans1 << ' ' << ans2 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define N 1000005
using namespace std;
int m[N];
int a, b, cnt, ans1, ans2;

int main() {
  while (1) {
    cin >> a >> b;
    if (!a && !b)
      break;
    memset(m, -1, sizeof(m));
    a %= b;
    cnt = 0;
    while (1) {
      a *= 10;
      if (m[a] != -1) {
        ans1 = m[a], ans2 = cnt - m[a];
        break;
      }
      m[a] = cnt;
      a %= b;
      if (!a) {
        ans1 = cnt + 1, ans2 = 0;
        break;
      }
      cnt++;
    }
    cout << ans1 << ' ' << ans2 << endl;
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
int m[1111111];
signed main() {
  int x, y;
  while (cin >> x >> y, x || y) {
    int c = 0;
    memset(m, -1, sizeof(m));
    while (m[x] < 0) {
      m[x] = c++;
      x = (x * 10) % y;
      if (!x)
        break;
    }
    if (!x)
      cout << c << " " << 0 << endl;
    else
      cout << m[x] << " " << c - m[x] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int x, y;
  while (cin >> x >> y, x || y) {
    map<int, int> m;
    int c = 0;
    while (!m.count(x)) {
      m[x] = c++;
      x = (x * 10) % y;
      if (!x)
        break;
    }
    if (!x)
      cout << c << " " << 0 << endl;
    else
      cout << m[x] << " " << c - m[x] << endl;
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

//============================================================================
// Name        : B.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

int x, y;

int dp[1000010];
pair<int, int> solve(int x, int y) {
  memset(dp, -1, sizeof dp);
  int c = x;
  for (int i = 0;; ++i) {
    // int q = c/y;
    int r = c % y;
    if (r == 0) {
      return make_pair(i, 0);
    }
    if (dp[r] != -1) {
      return make_pair(dp[r], i - dp[r]);
    }
    dp[r] = i;
    c = r * 10;
  }
}

int main() {
  while (cin >> x >> y && x) {
    auto ans = solve(x, y);
    cout << ans.first << ' ' << ans.second << '\\n';
  }
}

Error: TLE

Fixed submission:

//============================================================================
// Name        : B.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

int x, y;

pair<int, int> solve(int x, int y) {
  map<int, int> dp;
  int c = x;
  for (int i = 0;; ++i) {
    int q = c / y;
    int r = c % y;
    if (r == 0) {
      return make_pair(i, 0);
    }
    if (dp.count(r)) {
      return make_pair(dp[r], i - dp[r]);
    }
    dp[r] = i;
    c = r * 10;
  }
}

int main() {
  while (cin >> x >> y && x) {
    auto ans = solve(x, y);
    cout << ans.first << ' ' << ans.second << '\\n';
  }
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  while (cin >> x >> y, x) {
    int s[1000000] = {};
    int c = 0, gc = __gcd(x, y);
    x /= gc, y /= gc;
    while (!s[x]) {
      s[x] = ++c;
      x = (x * 10) % y;
    }
    if (x == 0)
      c = s[x] - 1;
    cout << s[x] - 1 << " " << c - s[x] + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  while (cin >> x >> y, x) {
    map<int, int> s;
    int c = 0, gc = __gcd(x, y);
    x /= gc, y /= gc;
    while (!s.count(x)) {
      s[x] = c++;
      x = (x * 10) % y;
    }
    if (x == 0)
      c = s[x];
    cout << s[x] << " " << c - s[x] << endl;
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = double;
const ld eps = 1e-9;

int adiv(int a) {
  map<int, int> mp;
  int num(a);
  for (int i = 2; i <= a; ++i) {
    while (num % i == 0) {
      mp[i]++;
      num /= i;
    }
  }
  int anum = 0;
  for (auto m : mp) {
    anum -= m.first;
  }
  anum += 2 * prev(mp.end())->first;
  return anum;
}

int main() {
  while (true) {

    int x, y;
    cin >> x >> y;
    if (!x)
      break;
    map<int, int> mp;
    vector<int> v(1e6 + 1, -1);
    int ans1 = 0, ans2 = 0;
    while (true) {
      x *= 10;
      int a = x / y;
      int b = x % y;

      if (b == 0) {
        ans1++;
        break;
      } else {
        if (v[x / 10] == -1) {
          v[x / 10] = ans1;
          ans1++;
          x = b;
        } else {
          ans2 = ans1 - v[x / 10];
          ans1 = v[x / 10];
          break;
        }
      }
    }
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = double;
const ld eps = 1e-9;

int adiv(int a) {
  map<int, int> mp;
  int num(a);
  for (int i = 2; i <= a; ++i) {
    while (num % i == 0) {
      mp[i]++;
      num /= i;
    }
  }
  int anum = 0;
  for (auto m : mp) {
    anum -= m.first;
  }
  anum += 2 * prev(mp.end())->first;
  return anum;
}

int main() {
  while (true) {

    int x, y;
    cin >> x >> y;
    if (!x)
      break;
    map<int, int> mp;
    vector<int> v(1e6 + 1, -1);
    int ans1 = 0, ans2 = 0;
    while (true) {
      x *= 10;
      int a = x / y;
      int b = x % y;

      if (b == 0) {
        ans1++;
        break;
      } else {
        if (v[x / 10] == -1) {
          v[x / 10] = ans1;
          ans1++;
          x = b;
        } else {
          ans2 = ans1 - v[x];
          ans1 = v[x];
          break;
        }
      }
    }
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}
Problem p01176 (C++) — buggy submission, verdict: Time Limit Exceeded

// Problem F : Controlled Tournament

#include <cstring>
#include <iostream>

using namespace std;

static int mem[16][1 << 16][5];
int vs[16][16];
int lg[16] = {1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};

// ツ講ツ評ツスツδ可イツドツつサツづ個づ慊づ慊づ個δδつ可サツ探ツ催オ
int search(int win, int lose, int cnt, int n) {
  if (cnt < 0)
    return 0;
  if (~mem[win][lose][cnt])
    return mem[win][lose][cnt];
  if (!lose)
    return mem[win][lose][cnt] = 1;
  int res = 0, loseBit = 0;
  for (int t = lose; t; t &= (t - 1))
    loseBit++;
  if (lg[loseBit] > cnt)
    return mem[win][lose][cnt] = 0;
  for (int i = 0; i < n; i++) {
    if (!(lose & (1 << i)))
      continue;
    if (!vs[win][i])
      continue;
    int mask = lose ^ (1 << i);
    int b = mask;
    do {
      res += search(win, b, cnt - 1, n) * search(i, mask ^ b, cnt - 1, n);
      b = (b - 1) & mask;
    } while (b != mask);
  }
  return mem[win][lose][cnt] = res;
}

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        cin >> vs[i][j];
    memset(mem, -1, sizeof(mem));
    cout << search(m - 1, (((1 << n) - 1) ^ (1 << (m - 1))), lg[n - 1], n)
         << endl;
  }
}

Error: TLE

Fixed submission:

// Problem F : Controlled Tournament

#include <cstring>
#include <iostream>

using namespace std;

static int mem[16][1 << 16][5];
int vs[16][16];
int lg[16] = {1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};

int search(int win, int lose, int cnt, int n) {
  if (cnt < 0)
    return 0;
  if (mem[win][lose][cnt] != -1)
    return mem[win][lose][cnt];
  if (lose == 0)
    return mem[win][lose][cnt] = 1;
  int ret = 0;
  int count = 0;
  int pos[16];
  for (int i = 0; i < n; i++) {
    if ((lose >> i) & 1) {
      pos[count] = i;
      count++;
    }
  }
  if (lg[count] > cnt)
    return mem[win][lose][cnt] = 0;
  for (int i = 0; i < (1 << count); i++) {
    int nLose = 0;
    for (int j = 0; j < count; j++) {
      if ((i >> j) & 1)
        nLose |= (1 << pos[j]);
    }
    for (int j = 0; j < count; j++) {
      if (vs[win][pos[j]] == 1 && ((nLose >> pos[j]) & 1)) {
        ret += search(win, nLose ^ lose, cnt - 1, n) *
               search(pos[j], nLose ^ (1 << pos[j]), cnt - 1, n);
      }
    }
  }
  mem[win][lose][cnt] = ret;
  return ret;
}

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        cin >> vs[i][j];
    memset(mem, -1, sizeof(mem));
    cout << search(m - 1, (((1 << n) - 1) ^ (1 << (m - 1))), lg[n - 1], n)
         << endl;
  }
}
Problem p01180 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e18;
typedef complex<double> P;
#define X real()
#define Y imag()
struct C {
  P p;
  double r;
  C(const P &p, const double &r) : p(p), r(r) {}
  C() {}
};
bool xcomp(const C &a, const C &b) {
  return (a.p.X != b.p.X) ? a.p.X < b.p.X : a.p.Y < b.p.Y;
}
bool ycomp(const C &a, const C &b) {
  return (a.p.Y != b.p.Y) ? a.p.Y < b.p.Y : a.p.X < b.p.X;
}

double closest(vector<C> &c, int first, int last, double rmax) {
  if (last - first <= 1)
    return INF;
  int mid = (first + last) / 2;
  double midx = c[mid].p.X;
  double d = min(closest(c, first, mid, rmax), closest(c, mid, last, rmax));
  inplace_merge(c.begin() + first, c.begin() + mid, c.begin() + last, ycomp);

  vector<C> near;
  for (int i = first; i < last; i++) {
    if (abs(c[i].p.X - midx) - c[i].r - rmax > d + EPS)
      continue;
    for (int j = near.size() - 1; j >= 0; j--) {
      if (abs(c[i].p.Y - near[j].p.Y) - c[i].r - rmax > d + EPS) {
        break;
      }
      d = min(d, abs(c[i].p - near[j].p) - c[i].r - near[j].r);
    }
    near.push_back(c[i]);
  }
  return d;
}

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

    vector<C> c(n);
    double rmax = 0;
    for (int i = 0; i < n; i++) {
      double r, x, y;
      cin >> r >> x >> y;
      c[i] = C(P(x, y), r);
      rmax = max(rmax, r);
    }
    sort(c.begin(), c.end(), xcomp);

    cout << fixed << setprecision(10);
    cout << closest(c, 0, n, rmax) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const double INF = 1e18;
typedef complex<double> P;
#define X real()
#define Y imag()
namespace std {
bool operator<(const P &a, const P &b) {
  return (a.X != b.X) ? a.X < b.X : a.Y < b.Y;
}
} // namespace std
P rotate(const P &p, double rad) { return p * P(cos(rad), sin(rad)); }

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

    vector<pair<P, double>> c(n);
    double rmax = 0;
    for (int i = 0; i < n; i++) {
      double r, x, y;
      cin >> r >> x >> y;
      c[i] = make_pair(rotate(P(x, y), 114514), r);
      rmax = max(rmax, r);
    }
    sort(c.begin(), c.end());

    double ans = INF;
    for (int i = 0; i < n; i++) {
      for (int j = i - 1; j >= 0; j--) {
        if ((c[j].first.X - c[i].first.X) - c[i].second - rmax > ans)
          break;
        ans =
            min(ans, abs(c[i].first - c[j].first) - c[i].second - c[j].second);
      }
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
  }
  return 0;
}