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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;
typedef complex<double> P;
struct C {
  P p;
  double r;
};
bool operator<(const C &c, const C &d) { return c.p.real() < d.p.real(); }

int main() {
  int n;
  while (cin >> n && n > 0) {
    vector<C> cs(n);
    double max_r = 0;
    double th = M_PI / 6;
    REP(i, n) {
      double r, x, y;
      cin >> r >> x >> y;

      P p(x, y);
      p *= polar(1.0, th);

      cs[i] = {p, r};

      max_r = max(max_r, r);
    }

    sort(cs.begin(), cs.end());
    double ans = 1e63;

    REP(i, n) {
      for (int j = i + 1; j < n; j++) {
        assert(cs[j].p.real() >= cs[i].p.real());
        if (ans < cs[j].p.real() - cs[i].p.real() - cs[i].r - max_r) {
          break;
        }
        ans = min(ans, abs(cs[i].p - cs[j].p) - cs[i].r - cs[j].r);
      }
    }
    printf("%.12f\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;
typedef complex<double> P;
struct C {
  P p;
  double r;
};
bool operator<(const C &c, const C &d) { return c.p.real() < d.p.real(); }

int main() {
  int n;
  while (cin >> n && n > 0) {
    vector<C> cs(n);
    double max_r = 0;
    REP(i, n) {
      double r, x, y;
      cin >> r >> x >> y;
      cs[i] = {{x, y}, r};

      max_r = max(max_r, r);
    }
    sort(cs.begin(), cs.end());
    double ans = 1e63;
    REP(i, n) {
      for (int j = i + 1; j < n; j++) {
        if (ans < cs[j].p.real() - cs[i].p.real() - cs[i].r - max_r) {
          break;
        }
        ans = min(ans, abs(cs[i].p - cs[j].p) - cs[i].r - cs[j].r);
      }
    }
    printf("%.12f\\n", ans);
  }
  return 0;
}
Problem p01180 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

struct Circle {
  double x, y, r;
  bool operator<(const Circle &) const;
};

bool Circle::operator<(const Circle &a) const {
  return (x * x + y * y) < (a.x * a.x + a.y * a.y);
}

double dist(const Circle &a, const Circle &b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) - a.r -
         b.r;
}

const int MAX_N = 100000;

int N;
Circle c[MAX_N];

vector<double> out;

int main() {
  do {
    scanf("%d", &N);
    if (N) {
      for (int i = 0; i < N; i++) {
        scanf("%lf %lf %lf", &c[i].r, &c[i].x, &c[i].y);
      }
      sort(c, c + N);
      double ans = 1e50;
      for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < min(N, i + 4001); j++) {
          ans = min(ans, dist(c[i], c[j]));
        }
      }
      out.push_back(ans);
    }
  } while (N);
  for (int i = 0; i < out.size(); i++) {
    printf("%.12f\\n", out[i]);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

struct Circle {
  double x, y, r;
  bool operator<(const Circle &) const;
};

bool Circle::operator<(const Circle &a) const {
  return (x * x + y * y) < (a.x * a.x + a.y * a.y);
}

double dist(const Circle &a, const Circle &b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) - a.r -
         b.r;
}

const int MAX_N = 100000;

int N;
Circle c[MAX_N];

vector<double> out;

int main() {
  do {
    scanf("%d", &N);
    if (N) {
      for (int i = 0; i < N; i++) {
        scanf("%lf %lf %lf", &c[i].r, &c[i].x, &c[i].y);
      }
      sort(c, c + N);
      double ans = 1e50;
      printf("%.8f\\n", ans);
      for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < min(N, i + 5001); j++) {
          ans = min(ans, dist(c[i], c[j]));
        }
      }
      out.push_back(ans);
    }
  } while (N);
  for (int i = 0; i < out.size(); i++) {
    printf("%.12f\\n", out[i]);
  }
  return 0;
}
Problem p01180 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

const int DIFF = 2000;

struct Circle {
  double x, y, r;
  bool operator<(const Circle &c) const {
    return sqrt(x * x + y * y) < sqrt(c.x * c.x + c.y * c.y);
  }
};

double dist(const Circle &c1, const Circle &c2) {
  return sqrt((c1.x - c2.x) * (c1.x - c2.x) + (c1.y - c2.y) * (c1.y - c2.y)) -
         c1.r - c2.r;
}

int main() {
  int n;
  while (cin >> n && n) {
    vector<Circle> V(n);
    for (int i = 0; i < n; i++)
      cin >> V[i].r >> V[i].x >> V[i].y;

    sort(V.begin(), V.end());

    double ans = 1e50;

    for (int i = 0; i < n; i++)
      for (int j = max(0, i - DIFF); j < min(n, i + DIFF); j++) {
        if (i == j)
          continue;
        ans = min(ans, dist(V[i], V[j]));
      }

    printf("%.5f\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

const int DIFF = 5000;

struct Circle {
  double x, y, r;
  bool operator<(const Circle &c) const {
    return sqrt(x * x + y * y) < sqrt(c.x * c.x + c.y * c.y);
  }
};

double dist(const Circle &c1, const Circle &c2) {
  return sqrt((c1.x - c2.x) * (c1.x - c2.x) + (c1.y - c2.y) * (c1.y - c2.y)) -
         c1.r - c2.r;
}

int main() {
  int n;
  while (cin >> n && n) {
    vector<Circle> V(n);
    for (int i = 0; i < n; i++)
      cin >> V[i].r >> V[i].x >> V[i].y;

    double ans = 1e50;

    for (int i = 0; i < n; i++)
      for (int j = max(0, i - DIFF); j < min(n, i + DIFF); j++) {
        if (i == j)
          continue;
        ans = min(ans, dist(V[i], V[j]));
      }

    printf("%.5f\\n", ans);
  }
  return 0;
}
Problem p01180 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct C {
  double r, x, y;
  C(double r, double x, double y) : r(r), x(x), y(y) {}
};

bool cmp_x(const C &a, const C &b) {
  return a.x == b.x ? a.y < b.y : a.x < b.x;
}
bool cmp_y(const C &a, const C &b) {
  return a.y == b.y ? a.x < b.x : a.y < b.y;
}

double dist(const C &a, const C &b) {
  double x = a.x - b.x;
  double y = a.y - b.y;
  return sqrt(x * x + y * y);
}
int main() {
  int n;
  while (cin >> n && n) {
    vector<C> a, b;
    for (int i = 0; i < n; i++) {
      double r, x, y;
      cin >> r >> x >> y;
      a.push_back(C(r, x, y));
      b.push_back(C(r, x, y));
    }
    double ans = 1e15;
    sort(a.begin(), a.end(), cmp_x);
    sort(b.begin(), b.end(), cmp_y);
    for (int i = 0; i < n; i++) {
      for (int j = max(0, i - 300); j < min(i + 300, n); j++) {
        if (i != j)
          ans = min(ans, dist(a[i], a[j]) - a[i].r - a[j].r);
      }
      for (int j = max(0, i - 300); j < min(i + 300, n); j++) {
        if (i != j)
          ans = min(ans, dist(b[i], b[j]) - b[i].r - b[j].r);
      }
    }
    printf("%.7f%c", ans, 10);
  }
}

Error: TLE

Fixed submission:

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

struct C {
  double r, x, y;
  C(double r, double x, double y) : r(r), x(x), y(y) {}
};

bool cmp_x(const C &a, const C &b) {
  return a.x == b.x ? a.y < b.y : a.x < b.x;
}
bool cmp_y(const C &a, const C &b) {
  return a.y == b.y ? a.x < b.x : a.y < b.y;
}

double dist(const C &a, const C &b) {
  double x = a.x - b.x;
  double y = a.y - b.y;
  return sqrt(x * x + y * y);
}
int main() {
  int n;
  while (cin >> n && n) {
    vector<C> a, b;
    for (int i = 0; i < n; i++) {
      double r, x, y;
      cin >> r >> x >> y;
      a.push_back(C(r, x, y));
      b.push_back(C(r, x, y));
    }
    double ans = 1e15;
    sort(a.begin(), a.end(), cmp_x);
    sort(b.begin(), b.end(), cmp_y);
    for (int i = 0; i < n; i++) {
      for (int j = max(0, i - 1000); j < min(i + 1000, n); j++) {
        if (i != j)
          ans = min(ans, dist(a[i], a[j]) - a[i].r - a[j].r);
      }
      for (int j = max(0, i - 1000); j < min(i + 1000, n); j++) {
        if (i != j)
          ans = min(ans, dist(b[i], b[j]) - b[i].r - b[j].r);
      }
    }
    cout << ans << endl;
  }
}
Problem p01181 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

int c[10];

bool check() {
  int sum = 0, MOD = c[9];
  rep(i, 3) sum = (sum + c[i]) % MOD;
  if ((c[3] + c[4] + c[5]) % MOD != sum)
    return false;
  if ((c[6] + c[7] + c[8]) % MOD != sum)
    return false;
  if ((c[0] + c[3] + c[6]) % MOD != sum)
    return false;
  if ((c[1] + c[4] + c[7]) % MOD != sum)
    return false;
  if ((c[2] + c[5] + c[8]) % MOD != sum)
    return false;
  if ((c[0] + c[4] + c[8]) % MOD != sum)
    return false;
  if ((c[2] + c[4] + c[6]) % MOD != sum)
    return false;
  return true;
}

int rec(int p, int S) {
  int res = 0;
  if (__builtin_popcount(S) == 10) {
    return check();
  }
  if (!c[p]) {
    rep(i, 10) {
      if ((S >> i) & 1)
        continue;
      c[p] = i + 1;
      res += rec(p + 1, S | (1 << i));
      c[p] = 0;
    }
  } else {
    res += rec(p + 1, S);
  }
  return res;
}

int main() {
  while (true) {
    int S = 0;
    bool EXIT = false;
    rep(i, 10) {
      cin >> c[i];
      if (c[i] > 0) {
        S |= 1 << (c[i] - 1);
      } else if (c[i] == -1) {
        EXIT = true;
      }
    }
    if (EXIT)
      break;
    cout << rec(0, S) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

int c[10];

bool check() {
  int sum = 0, MOD = c[9];
  rep(i, 3) sum = (sum + c[i]) % MOD;
  if ((c[3] + c[4] + c[5]) % MOD != sum)
    return false;
  if ((c[6] + c[7] + c[8]) % MOD != sum)
    return false;
  if ((c[0] + c[3] + c[6]) % MOD != sum)
    return false;
  if ((c[1] + c[4] + c[7]) % MOD != sum)
    return false;
  if ((c[2] + c[5] + c[8]) % MOD != sum)
    return false;
  return true;
}

int rec(int p, int S) {
  int res = 0;
  if (p == 9) {
    return check();
  }
  if (!c[p]) {
    rep(i, 10) {
      if ((S >> i) & 1)
        continue;
      c[p] = i + 1;
      res += rec(p + 1, S | (1 << i));
      c[p] = 0;
    }
  } else {
    res += rec(p + 1, S);
  }
  return res;
}

int main() {
  while (true) {
    int S = 0;
    bool EXIT = false;
    rep(i, 10) {
      cin >> c[i];
      if (c[i] > 0) {
        S |= 1 << (c[i] - 1);
      } else if (c[i] == -1) {
        EXIT = true;
      }
    }
    if (EXIT)
      break;
    cout << rec(0, S) << endl;
  }
  return 0;
}
Problem p01181 (C++) — buggy submission, verdict: Runtime Error

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

bool isvalid(const vector<int> &b, int m) {
  int target = -1;
  for (int i = 0; i < 3; ++i) {
    int t1 = 0, t2 = 0;
    for (int j = 0; j < 3; ++j) {
      t1 += b[i * 3 + j];
      t2 += b[j * 3 + i];
    }
    t1 %= m, t2 %= m;
    if (target == -1)
      target = t1;
    if (t1 != target || t2 != target)
      return false;
  }

  int tt = b[0] + b[4] + b[8], tt2 = b[2] + b[4] + b[6];

  tt %= m, tt2 %= m;
  if (tt != target || tt2 != target)
    return false;

  return true;
}

int dfs(vector<int> &b, int used, int remain) {
  if (remain == 0)
    return (isvalid(b, b[9])) ? 1 : 0;

  int next = 0, ret = 0;
  while (b[next] != 0)
    next++;

  for (int use = 1; use <= 10; ++use) {
    if ((used >> use) & 1)
      continue;
    b[next] = use;
    ret += dfs(b, used | (1 << use), remain - 1);
    b[next] = 0;
  }

  return ret;
}

int main() {
  vector<int> b(10, 0);
  while (true) {
    for (int i = 0; i < 10; ++i)
      cin >> b[i];
    for (int i = 0; i < 10; ++i) {
      if (b[i] != -1)
        break;
      if (i == 9)
        goto END;
    }

    int used = 1, rem = 0;
    for (int i = 0; i < 10; ++i) {
      used |= (1 << (b[i]));
      if (b[i] == 0)
        rem++;
    }

    cout << dfs(b, used, rem) << endl;
  }
END:;
}

Error: 0

Fixed submission:

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

bool isvalid(const vector<int> &b, int m) {
  int target = -1;
  for (int i = 0; i < 3; ++i) {
    int t1 = 0, t2 = 0;
    for (int j = 0; j < 3; ++j) {
      t1 += b[i * 3 + j];
      t2 += b[j * 3 + j];
    }
    t1 %= m, t2 %= m;
    if (target == -1)
      target = t1;
    if (t1 != target || t2 != target)
      return false;
  }
  return true;
}

int pop(int x) {
  int n = 0;
  while (x != 0) {
    n++;
    x &= (x - 1);
  }
  return n;
}

int dfs(vector<int> &b, int m, int used) {

  if (pop(used) == 11) {
    return (isvalid(b, m)) ? 1 : 0;
  }

  int ret = 0, next = 0;
  while (b[next] != 0)
    next++;
  for (int use = 1; use <= 10; ++use) {
    if ((used >> use) & 1)
      continue;
    b[next] = use;
    ret += dfs(b, m, used | (1 << use));
    b[next] = 0;
  }

  return ret;
}

int main() {
  vector<int> b(10, 0);
  while (true) {
    for (int i = 0; i < 10; ++i)
      cin >> b[i];
    for (int i = 0; i < 10; ++i) {
      if (b[i] != -1)
        break;
      if (i == 9)
        goto END;
    }

    int used = 1;
    for (int i = 0; i < 10; ++i)
      used |= (1 << (b[i]));
    cout << dfs(b, b[9], used) << endl;
  }
END:;
}
Problem p01181 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int m;
vi tmp;
int w[8][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6},
               {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}};
vi in;
bool f() {
  vi su(8);
  rep(i, 8) {
    int sum = 0;
    rep(j, 3) sum += tmp[w[i][j]];
    su[i] = sum % m;
  }
  bool h = true;
  rep(i, 8) if (su[0] != su[i]) h = false;
  return h;
}
int main() {
  while (1) {
    in = vi(10);
    rep(i, 10) cin >> in[i];
    if (in[0] == -1)
      break;
    tmp = vi(11);
    rep(i, 10) tmp[in[i]]++;
    vi per;
    rep(i, 10) if (tmp[i + 1] == 0) per.pb(i + 1);
    int out = 0;
    do {
      tmp = in;
      int c = 0;
      rep(i, 10) if (tmp[i] == 0) tmp[i] = per[c], c++;
      m = tmp[9];
      out += f();
    } while (next_permutation(all(per)));
    cout << out << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int m;
vi tmp;
int w[8][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6},
               {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}};
vi in;
bool f() {
  vi su(8);
  rep(i, 8) {
    int sum = 0;
    rep(j, 3) sum += tmp[w[i][j]];
    su[i] = sum % m;
  }
  bool h = true;
  rep(i, 8) if (su[0] != su[i]) h = false;
  return h;
}
int main() {
  while (1) {
    in = vi(10);
    rep(i, 10) cin >> in[i];
    if (in[0] == -1)
      break;
    m = in[9];
    tmp = vi(11);
    rep(i, 10) tmp[in[i]]++;
    int t = tmp[0];
    vi per;
    rep(i, 10) if (tmp[i + 1] == 0) per.pb(i + 1);
    int out = 0;
    do {
      tmp = in;
      int c = 0;
      rep(i, 10) if (tmp[i] == 0) tmp[i] = per[c], c++;
      out += f();
    } while (next_permutation(all(per)));
    cout << out << endl;
  }
}
Problem p01181 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

bool used[11];
int num[11];
int cnt;

void dfs(int pos) {
  if (pos == 10) {
    int tmp = -1;
    int mod = num[9];
    for (int i = 0; i < 3; i++) {
      int sum = 0;
      for (int j = 0; j < 3; j++)
        sum += num[i * 3 + j];
      if (tmp == -1)
        tmp = sum % mod;
      else if (tmp != sum % mod)
        return;
    }
    for (int j = 0; j < 3; j++) {
      int sum = 0;
      for (int i = 0; i < 3; i++)
        sum += num[i * 3 + j];
      if (tmp == -1)
        tmp = sum % mod;
      else if (tmp != sum % mod)
        return;
    }
    int sum = num[0] + num[4] + num[8];
    int sum2 = num[2] + num[4] + num[6];
    if (tmp == sum % mod && tmp == sum2 % mod)
      cnt++;
  } else {
    if (num[pos] == 0) {
      for (int i = 1; i <= 10; i++) {
        if (!used[i]) {
          used[i] = true;
          num[pos] = i;
          dfs(pos + 1);
          used[i] = false;
          num[pos] = 0;
        }
      }
    } else
      dfs(pos + 1);
  }
}

int main() {

  while (cin >> num[0] && num[0] != -1) {
    memset(used, 0, sizeof(used));
    if (num[0] != 0)
      used[num[0]] = true;
    for (int i = 1; i < 10; i++) {
      cin >> num[i];
      if (num[i] != 0)
        used[num[i]] = true;
    }
    dfs(0);
    cout << cnt << endl;
    cnt = 0;
  }
  for (int i = 1; i < 10; i++)
    cin >> num[i];

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

bool used[11];
int num[10];
int mod;
int cnt;

void dfs(int pos) {
  if (pos == 9) {
    int tmp = -1;
    for (int i = 0; i < 3; i++) {
      int sum = 0;
      for (int j = 0; j < 3; j++)
        sum += num[i * 3 + j];
      if (tmp == -1)
        tmp = sum % mod;
      else if (tmp != sum % mod)
        return;
    }
    for (int j = 0; j < 3; j++) {
      int sum = 0;
      for (int i = 0; i < 3; i++)
        sum += num[i * 3 + j];
      if (tmp == -1)
        tmp = sum % mod;
      else if (tmp != sum % mod)
        return;
    }
    int sum = num[0] + num[4] + num[8];
    int sum2 = num[2] + num[4] + num[6];
    if (tmp == sum % mod && tmp == sum2 % mod)
      cnt++;
  } else {
    if (num[pos] == 0) {
      for (int i = 1; i <= 10; i++) {
        if (!used[i]) {
          used[i] = true;
          num[pos] = i;
          dfs(pos + 1);
          used[i] = false;
          num[pos] = 0;
        }
      }
    } else
      dfs(pos + 1);
  }
}

int main() {

  while (cin >> num[0] && num[0] != -1) {
    memset(used, 0, sizeof(used));
    for (int i = 1; i < 9; i++) {
      cin >> num[i];
      if (num[i] != 0)
        used[num[i]] = true;
    }
    cin >> mod;
    dfs(0);
    cout << cnt << endl;
    cnt = 0;
  }
  for (int i = 1; i < 10; i++)
    cin >> num[i];

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

#include <algorithm>
#include <cmath>
#include <cstdio>

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

using namespace std;

// 三角形が作れるかどうか
bool tri(int a, int b, int c) {
  int p[] = {a, b, c};
  sort(p, p + 3);
  return p[0] + p[1] > p[2];
}

double volume(double U, double V, double W, double u, double v, double w) {
  double X = (w - U + v) * (U + v + w);
  double x = (U - v + w) * (v - w + U);
  double Y = (u - V + w) * (V + w + u);
  double y = (V - w + u) * (w - u + V);
  double Z = (v - W + u) * (W + u + v);
  double z = (W - u + v) * (u - v + W);
  double a = sqrt(x * Y * Z);
  double b = sqrt(y * Z * X);
  double c = sqrt(z * X * Y);
  double d = sqrt(x * y * z);
  return sqrt((-a + b + c + d) * (a - b + c + d) * (a + b - c + d) *
              (a + b + c - d)) /
         (192 * u * v * w);
}

int main() {
  for (int n; scanf("%d", &n), n;) {
    int L[15];
    rep(i, n) scanf("%d", L + i);

    double ans = 0;
    int p[15] = {1, 1, 1, 1, 1, 1};
    do {
      int m = 0, q[6];
      rep(i, n) if (p[i] == 1) q[m++] = i;
      do {
        int a = L[q[0]];
        int b = L[q[1]];
        int c = L[q[2]];
        int d = L[q[3]];
        int e = L[q[4]];
        int f = L[q[5]];
        if (tri(a, b, c) && tri(a, e, f) && tri(b, f, d) && tri(c, d, e))
          ans = max(ans, volume(a, b, c, d, e, f));
      } while (next_permutation(q, q + 5)); // 一つの辺は固定していい
    } while (prev_permutation(p, p + n));

    printf("%.9f\\n", ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>

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

using namespace std;

// 三角形が作れるかどうか
bool tri(int a, int b, int c) {
  int p[] = {a, b, c};
  sort(p, p + 3);
  return p[0] + p[1] > p[2];
}

double volume(double U, double V, double W, double u, double v, double w) {
  double X = (w - U + v) * (U + v + w);
  double x = (U - v + w) * (v - w + U);
  double Y = (u - V + w) * (V + w + u);
  double y = (V - w + u) * (w - u + V);
  double Z = (v - W + u) * (W + u + v);
  double z = (W - u + v) * (u - v + W);
  double a = sqrt(x * Y * Z);
  double b = sqrt(y * Z * X);
  double c = sqrt(z * X * Y);
  double d = sqrt(x * y * z);
  return sqrt((-a + b + c + d) * (a - b + c + d) * (a + b - c + d) *
              (a + b + c - d)) /
         (192 * u * v * w);
}

int main() {
  for (int n; scanf("%d", &n), n;) {
    int L[15];
    rep(i, n) scanf("%d", L + i);

    double ans = 0;
    rep(a, n) rep(b, n) if (a != b) rep(c, n) if (a != c && b != c)
        rep(d, n) if (a != d && b != d && c != d)
            rep(e, n) if (a != e && b != e && c != e && d != e)
                rep(f, n) if (a != f && b != f && c != f && d != f && e != f) {
      if (tri(L[a], L[b], L[c]) && tri(L[a], L[e], L[f]) &&
          tri(L[b], L[f], L[d]) && tri(L[c], L[d], L[e]))
        ans = max(ans, volume(L[a], L[b], L[c], L[d], L[e], L[f]));
    }
    printf("%.9f\\n", ans);
  }

  return 0;
}