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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
#define Max 110
#define LL long long

double l[Max], a[Max], b[Max];
double dis[Max][Max], num[Max];
LL temp[Max];

// void init ()
//{
//	LL ans = 0, x;
//	for (LL i = 0;i <= 30;i ++)
//	{
//		x = i;
//		ans = 0;
//		while(x)
//		{
//			if(x % 2 == 1)
//				ans ++;
//			x /= 2;
//		}
//		num[i] = ans;
//	}
// }

LL judge(LL x) {
  LL ans = 0;

  while (x) {
    if (x % 2 == 1)
      ans++;
    x /= 2;
  }
  return ans;
}

double cal(LL x) {
  double ans = 0.0;
  LL cnt = 0;
  for (LL i = 1; x; i++) {
    if (x % 2 == 1) {
      temp[++cnt] = i;
      for (LL j = 1; j < cnt; j++) {
        ans += dis[i][temp[j]];
      }
    }
    x /= 2;
  }
  return ans;
}

double MAX(double a, double b) { return a > b ? a : b; }

int main() {
  // init ();
  LL n, m, i, j, k;
  while (scanf("%lld%lld", &n, &m) == 2) {
    for (i = 1; i <= n; i++) {
      scanf("%lf%lf%lf", &l[i], &a[i], &b[i]);
      for (j = 1; j < i; j++) {
        dis[i][j] = dis[j][i] = (l[i] - l[j]) * (l[i] - l[j]) +
                                (a[i] - a[j]) * (a[i] - a[j]) +
                                (b[i] - b[j]) * (b[i] - b[j]);
      }
    }

    if (m <= 1 || n == 0) {
      printf("0.00000000000000000000\\n");
      continue;
    }
    double ans = 0.0;
    for (i = 1; i < (1 << n); i++) {
      // if (num[i] == m)
      if (judge(i) == m) {
        double temp = cal(i);
        ans = MAX(ans, temp);
      }
    }
    printf("%.20lf\\n", ans);
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
#define Max 31
#define LL long long

double l[Max], a[Max], b[Max], dis[Max][Max];

LL num[Max];

void init() {
  LL ans = 0, x;
  for (LL i = 1; i <= 22; i++) {
    x = i;
    ans = 0;
    while (x) {
      if (x % 2 == 1)
        ans++;
      x /= 2;
    }
    num[i] = ans;
  }
}

double cal(long long x) {
  double ans = 0;
  LL cnt = 0, temp[21], i, j;
  for (i = 1; x; i++) {
    if (x & 1) {
      temp[++cnt] = i;
      for (j = 1; j < cnt; j++) {
        ans += dis[i][temp[j]];
      }
    }
    x >>= 1;
  }
  return ans;
}

double MAX(double a, double b) { return a > b ? a : b; }

int main() {
  init();
  LL n, m, i, j;
  double ans = -1;
  scanf("%lld%lld", &n, &m);

  for (i = 1; i <= n; i++) {
    scanf("%lf%lf%lf", &l[i], &a[i], &b[i]);
    for (j = 1; j < i; j++) {
      dis[i][j] = dis[j][i] = (l[i] - l[j]) * (l[i] - l[j]) +
                              (a[i] - a[j]) * (a[i] - a[j]) +
                              (b[i] - b[j]) * (b[i] - b[j]);
    }
  }
  if (m <= 1 || n == 0) {
    printf("0.00000000000000000000\\n");
  } else {
    LL nn = (1 << n);
    for (i = 1; i < nn; i++) {
      if (num[i] == m) {
        ans = (double)MAX(ans, cal(i));
      }
    }

    printf("%.20lf\\n", ans);
  }
}
Problem p01417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

int i, j;
int nn, mm;
double l[100];
double a[100];
double b[100];
double core[100][100];

int s[100];
double maxx = 0.0;
void print(int N) {
  double num = 0.0;
  for (int ii = 1; ii <= N; ii++) {
    for (int jj = 1; jj <= N; jj++) {
      // printf("ii=%d jj=%d\\n",s[ii],s[jj]);
      num += core[s[ii]][s[jj]];
    }
    // printf("\\n");
  }
  if (num > maxx) {
    maxx = num;
  }
}
void zuhe(int a, int n, int M, int N) {
  if (n <= N) {
    int i;
    for (int ii = a; ii <= M - N + n; ii++) {
      s[n] = ii;
      if (n == N)
        print(N);
      else
        zuhe(a + 1, n + 1, M, N);
      a++;
    }
  }
}

int main() {
  scanf("%d%d", &nn, &mm);
  if (mm == 1) {
    printf("0.00000000000000000000\\n");
    return 0;
  }
  for (i = 1; i <= nn; i++) {
    scanf("%lf%lf%lf", &l[i], &a[i], &b[i]);
  }
  int topp = 0;

  for (i = 1; i <= nn; i++) {
    // printf("%.20f\\n",(l[i]*l[i]+a[i]*a[i]+b[i]*b[i]));
  }

  for (i = 1; i <= nn; i++) {
    for (j = 1; j <= nn; j++) {

      core[i][j] =
          ((l[i] - l[j]) * (l[i] - l[j]) + (a[i] - a[j]) * (a[i] - a[j]) +
           (b[i] - b[j]) * (b[i] - b[j]));
      // printf("%.2f ",core[i][j]);
    }
    // printf("\\n");
  }
  zuhe(1, 1, nn, mm);
  printf("%.20f\\n", maxx / 2);

  // system("pause");
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int n, m;
double L[30], a[30], b[30];
double sum;
double cpp[30];
double findsum(int k) {
  double ans = 0;
  for (int i = 0; i < k; i++) {
    int x = cpp[i];
    int y = cpp[k];
    ans += (L[x] - L[y]) * (L[x] - L[y]) + (a[x] - a[y]) * (a[x] - a[y]) +
           (b[x] - b[y]) * (b[x] - b[y]);
  }
  return ans;
}
void dfs(int k, int cid, double csum) {
  if (k == m) {
    if (csum > sum)
      sum = csum;
    return;
  }
  if (cid == n) {
    return;
  }
  for (int i = cid; i < n; i++) {
    cpp[k] = i;
    double newsum1 = findsum(k);
    dfs(k + 1, i + 1, csum + newsum1);
    dfs(k, i + 1, csum);
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++)
      scanf("%lf%lf%lf", &L[i], &a[i], &b[i]);
    sum = 0;
    memset(cpp, 0, sizeof(cpp));
    dfs(0, 0, 0);
    printf("%.6lf\\n", sum);
  }
  return 0;
}
Problem p01417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>
#include <stdio.h>
#include <string.h>
#define MAX 25
double x[MAX], y[MAX], z[MAX], Dis[MAX][MAX], Max;
int N, M, ipos[MAX];
double dis(int n, int m) {
  return pow(x[n] - x[m], 2) + pow(y[n] - y[m], 2) + pow(z[n] - z[m], 2);
}
void dfs(int cur, int count, double ans) {
  double k = ans;
  int i;
  if (count == M) {
    if (Max < ans)
      Max = ans;
    return;
  }
  if (cur >= N)
    return;
  if (count > M)
    return;
  dfs(cur + 1, count, ans);
  ipos[cur] = 1;
  for (i = 0; i < cur; i++) {
    if (ipos[i] == 1)
      k += Dis[i][cur];
  }
  dfs(cur + 1, count + 1, k);
  ipos[cur] = 0;
  return;
}
int main() {
  int i, j;
  while (scanf("%d%d", &N, &M) != EOF) {
    for (i = 0; i < N; i++)
      scanf("%lf%lf%lf", &x[i], &y[i], &z[i]);
    memset(Dis, 0, sizeof(Dis));
    memset(ipos, 0, sizeof(ipos));
    Max = 0;
    for (i = 0; i < N; i++)
      for (j = i + 1; j < N; j++)
        Dis[i][j] = dis(i, j);
    dfs(0, 0, 0);
    printf("%.20lf\\n", Max);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define eps 0.000001

int n, m;
double dis[21][21], max1 = 0;
double x[21], y[21], z[21];
bool vis[21] = {0};
void cal(int sta, int re) {
  if (re == 0) {
    double pp = 0;
    for (int i = 0; i < n; i++) {
      if (vis[i])
        continue;
      for (int j = 0; j < n; j++) {
        if (vis[j])
          continue;
        pp = pp + dis[i][j];
      }
    }
    if (pp > max1)
      max1 = pp;
    int kk = 0;
  }
  for (int i = sta; i < n; i++) {
    vis[i] = 1;
    cal(i + 1, re - 1);
    vis[i] = 0;
    cal(i + 1, re);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    scanf("%lf%lf%lf", x + i, y + i, z + i);
  if (m == 1 || m == 0)
    printf("%.20lf\\n", 0);
  else {
    double max = 0;
    int mx, my;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        double d1 = x[i] - x[j], d2 = y[i] - y[j], d3 = z[i] - z[j];
        dis[i][j] = dis[j][i] = d1 * d1 + d2 * d2 + d3 * d3;
      }
    cal(0, n - m);
    printf("%.20lf\\n", max1 / 2);
  }
  return 0;
}
Problem p01417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
double L[21], a[21], b[21];
int n, m;
int bit_count(int bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

double comp(int k) {
  vector<int> lab;
  for (int i = 0; i < n; i++)
    if ((k & (1 << i)) != 0)
      lab.push_back(i);

  double sum = 0;
  for (int i = 0; i < lab.size(); i++)
    for (int j = i + 1; j < lab.size(); j++) {
      double x = L[lab[i]] - L[lab[j]];
      double y = a[lab[i]] - a[lab[j]];
      double z = b[lab[i]] - b[lab[j]];
      double xyz = x * x + y * y + z * z;
      sum += xyz;
    }
  return sum;
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> L[i] >> a[i] >> b[i];

  double ans = 0;
  for (int i = 0; i < (1 << n); i++)
    if (bit_count(i) == m)
      ans = max(ans, comp(i));

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#define L first
#define a second.first
#define b second.second
using namespace std;
typedef pair<double, pair<double, double>> P;
int n, m;
P lab[21];
int used[21];
int memo[21][21];
double ans;

void saiki(double sum, int cnt) {
  if (cnt == m && sum > ans)
    ans = sum;
  if (cnt <= m)
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        if (memo[i][j] == 1)
          continue;
        memo[i][j] = 1;
        double x = (lab[i].L - lab[j].L);
        double y = (lab[i].a - lab[j].a);
        double z = (lab[i].b - lab[j].b);
        double xyz = x * x + y * y + z * z;
        if (used[i] == 1 && used[j] == 1)
          saiki(sum + xyz, cnt);
        else if (used[i] == 0 && used[j] == 0) {
          used[i] = used[j] = 1;
          saiki(sum + xyz, cnt + 2);
          used[i] = used[j] = 0;
        } else if (used[i] == 0) {
          used[i] = 1;
          saiki(sum + xyz, cnt + 1);
          used[i] = 0;
        } else if (used[j] == 0) {
          used[j] = 1;
          saiki(sum + xyz, cnt + 1);
          used[j] = 0;
        }
        memo[i][j] = 0;
      }
}

int main() {

  cin >> n >> m;

  for (int i = 0; i < n; i++)
    cin >> lab[i].L >> lab[i].a >> lab[i].b;
  ans = 0;
  saiki(0, 0);
  printf("%.10f\\n", ans);

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

#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
double a[21][3], ans = 0, p;
int n, m, c[21];
using namespace std;
double cal() {
  p = 0;
  r(i, 0, m) r(j, i + 1, m) p += pow(a[c[i]][0] - a[c[j]][0], 2) +
                                 pow(a[c[i]][1] - a[c[j]][1], 2) +
                                 pow(a[c[i]][2] - a[c[j]][2], 2);
  ans = max(ans, p);
}
void dfs(int x, int d) {
  if (d == m) {
    cal();
    return;
  } else if (x == n)
    return;
  c[d] = x;
  dfs(x + 1, d + 1);
  dfs(x + 1, d);
}
int main() {
  cin >> n >> m;
  r(i, 0, n) cin >> a[i][0] >> a[i][1] >> a[i][2];
  dfs(0, 0);
  printf("%.6f\\n", ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
long double a[21][3], ans = 0, p;
int n, m, c[21];
using namespace std;
double cal() {
  p = 0;
  r(i, 0, m) r(j, i + 1, m) p += pow(a[c[i]][0] - a[c[j]][0], 2) +
                                 pow(a[c[i]][1] - a[c[j]][1], 2) +
                                 pow(a[c[i]][2] - a[c[j]][2], 2);
  ans = max(ans, p);
}
void dfs(int x, int d) {
  if (d == m) {
    cal();
    return;
  } else if (x == n)
    return;
  c[d] = x;
  dfs(x + 1, d + 1);
  dfs(x + 1, d);
}
int main() {
  while (cin >> n >> m, n) {
    r(i, 0, n) cin >> a[i][0] >> a[i][1] >> a[i][2];
    dfs(0, 0);
    printf("%.12f\\n", ans);
  }
}
Problem p01417 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
#define rep(i, b) for (int i = 0; i < b; i++)
#define repi(i, a, b) for (int i = a; i < b; i++)
typedef vector<int> vec;
#define eps 1e-10

struct C {
  double l, a, b;
};

int N, M;
double ans = 0;
vector<C> c;

double dist(C c1, C c2) {
  return pow(c1.l - c2.l, 2) + pow(c1.a - c2.a, 2) + pow(c1.b - c2.b, 2);
}

void dfs(int d, vec v) {
  if (d == M) {
    double sum = 0;
    rep(i, v.size()) repi(j, i + 1, v.size()) { sum += dist(c[v[i]], c[v[j]]); }
    // cout << 'ans:' << ans << endl;
    ans = max(ans, sum);
  } else {
    repi(i, v[d - 1] + 1, N) {
      v.push_back(i);
      dfs(d + 1, v);
      v.pop_back();
    }
  }
}

int main() {
  cin >> N >> M;
  rep(i, N) {
    C t;
    cin >> t.l >> t.a >> t.b;
    c.push_back(t);
  }
  vec v;

  rep(i, N) {
    v.push_back(i);
    dfs(1, v);
    v.pop_back();
  }
  printf("%.20f\\n", ans);
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stack>
#include <vector>
using namespace std;
#define rep(i, b) for (int i = 0; i < b; i++)
#define repi(i, a, b) for (int i = a; i < b; i++)
typedef vector<int> vec;
#define eps 1e-10

struct C {
  double l, a, b;
};

int N, M;
double ans = 0;
vector<C> c;

double dist(C c1, C c2) {
  return pow(c1.l - c2.l, 2) + pow(c1.a - c2.a, 2) + pow(c1.b - c2.b, 2);
}

void dfs(int d, vec v) {
  if (d == M) {
    double sum = 0;
    rep(i, v.size()) repi(j, i + 1, v.size()) { sum += dist(c[v[i]], c[v[j]]); }
    cout << 'ans:' << ans << endl;
    ans = max(ans, sum);
  } else {
    repi(i, v[d - 1] + 1, N) {
      v.push_back(i);
      dfs(d + 1, v);
      v.pop_back();
    }
  }
}

int main() {
  while (cin >> N >> M, N) {
    rep(i, N) {
      C t;
      cin >> t.l >> t.a >> t.b;
      c.push_back(t);
    }
    vec v;

    rep(i, N) {
      v.push_back(i);
      dfs(1, v);
      v.pop_back();
    }
    cout << ans << endl;
  }
}
Problem p01417 (C++) — buggy submission, verdict: Runtime Error

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

double r[21], g[21], b[21];

double dabs(double d) {
  if (d < 0)
    return -d;
  return d;
}

inline unsigned next_set(unsigned x) {
  unsigned smallest = x & -x;
  unsigned ripple = x + smallest;
  unsigned new_smallest = ripple & -ripple;
  unsigned ones = ((new_smallest / smallest) >> 1) - 1;
  return ripple | ones;
}

double diff(int i, int j) {
  return dabs(r[i] - r[j]) * dabs(r[i] - r[j]) +
         dabs(g[i] - g[j]) * dabs(g[i] - g[j]) +
         dabs(b[i] - b[j]) * dabs(b[i] - b[j]);
}

int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << "0" << endl;
    return 0;
  }

  for (int i = 0; i < n; ++i)
    cin >> r[i] >> g[i] >> b[i];

  unsigned st = (1 << m) - 1;
  double ans = 0;
  while (st < (1 << n)) {
    double tmp = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if ((1 << i) & st) {
          if ((1 << j) & st) {
            tmp += diff(i, j);
          }
        }
      }
    }
    ans = max(ans, tmp);
    st = next_set(st);
  }
  printf("%.12f\\n", ans);
}

Error: WA

Fixed submission:

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

double r[21], g[21], b[21];

double dabs(double d) {
  if (d < 0)
    return -d;
  return d;
}

inline int next_set(int x) {
  int smallest = x & -x;
  int ripple = x + smallest;
  int new_smallest = ripple & -ripple;
  int ones = ((new_smallest / smallest) >> 1) - 1;
  return ripple | ones;
}

double diff(int i, int j) {
  return dabs(r[i] - r[j]) * dabs(r[i] - r[j]) +
         dabs(g[i] - g[j]) * dabs(g[i] - g[j]) +
         dabs(b[i] - b[j]) * dabs(b[i] - b[j]);
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    cin >> r[i] >> g[i] >> b[i];

  int st = (1 << m) - 1;
  double ans = 0;
  while (st < (1 << n)) {
    double tmp = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if ((1 << i) & st) {
          if ((1 << j) & st) {
            tmp += diff(i, j);
          }
        }
      }
    }
    ans = max(ans, tmp);
    st = next_set(st);
  }
  printf("%.12f\\n", ans);
}
Problem p01417 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N, M;
  cin >> N >> M;
  if (M == 0) {
    cout << 0 << endl;
    return 0;
  }
  vector<double> L(N), a(N), b(N);
  for (int i = 0; i < N; i++)
    cin >> L[i] >> a[i] >> b[i];
  vector<vector<double>> d(N, vector<double>(N));
  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < N; j++) {
      double dL = L[i] - L[j], da = a[i] - a[j], db = b[i] - b[j];
      d[i][j] = dL * dL + da * da + db * db;
    }
  double maxi = 0;
  for (int S = (1 << M) - 1; S < (1 << N);) {
    double sum = 0;
    for (int i = 0; i < N; i++)
      for (int j = i + 1; j < N; j++)
        if ((S & (1 << i)) && (S & (1 << j)))
          sum += d[i][j];
    maxi = max(maxi, sum);
    int x = S & -S, y = S + x;
    S = ((S & ~y) / x >> 1) | y;
  }
  printf("%.10f\\n", maxi);
}

Error: WA

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N, M;
  cin >> N >> M;
  vector<double> L(N), a(N), b(N);
  for (int i = 0; i < N; i++)
    cin >> L[i] >> a[i] >> b[i];
  vector<vector<double>> d(N, vector<double>(N));
  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < N; j++) {
      double dL = L[i] - L[j], da = a[i] - a[j], db = b[i] - b[j];
      d[i][j] = dL * dL + da * da + db * db;
    }
  double maxi = 0;
  for (int S = (1 << M) - 1; S < (1 << N);) {
    double sum = 0;
    for (int i = 0; i < N; i++)
      for (int j = i + 1; j < N; j++)
        if ((S & (1 << i)) && (S & (1 << j)))
          sum += d[i][j];
    maxi = max(maxi, sum);
    int x = S & -S, y = S + x;
    S = ((S & ~y) / x >> 1) | y;
  }
  printf("%.10f\\n", maxi);
}
Problem p01417 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>

int main() {
  for (int n, m; ~scanf("%d%d", &n, &m);) {
    double l[20], a[20], b[20];
    for (int i = 0; i < n; i++)
      scanf("%lf%lf%lf", l + i, a + i, b + i);

    if (m == 0) {
      puts("0");
      continue;
    }

    double res = 0;
    for (int s = (1 << m) - 1; !(s & 1 << n);) {
      double sum = 0;
      for (int i = 0; i < n; i++)
        if (s >> i & 1)
          for (int j = i + 1; j < n; j++)
            if (s >> j & 1)
              sum += pow(l[i] - l[j], 2) + pow(a[i] - a[j], 2) +
                     pow(b[i] - b[j], 2);
      if (res < sum)
        res = sum;
      int lo = s & -s, lz = (s + lo) & ~s;
      s = (s | lz) & ~(lz - 1);
      s |= (lz / lo / 2 - 1);
    }

    printf("%f\\n", res);
  }

  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <cstdio>

int main() {
  for (int n, m; ~scanf("%d%d", &n, &m);) {
    if (n == 0) {
      puts("0");
      continue;
    }

    double l[n], a[n], b[n];
    for (int i = 0; i < n; i++)
      scanf("%lf%lf%lf", l + i, a + i, b + i);

    double res = 0;
    for (int s = (1 << m) - 1; !(s & 1 << n);) {
      double sum = 0;
      for (int i = 0; i < n; i++)
        if (s >> i & 1)
          for (int j = i + 1; j < n; j++)
            if (s >> j & 1)
              sum += pow(l[i] - l[j], 2) + pow(a[i] - a[j], 2) +
                     pow(b[i] - b[j], 2);
      if (res < sum)
        res = sum;
      int lo = s & -s, lz = (s + lo) & ~s;
      s = (s | lz) & ~(lz - 1);
      s |= (lz / lo / 2 - 1);
    }

    printf("%f\\n", res);
  }

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

#include <iomanip>
#include <iostream>
using namespace std;
int K, L, R;
double P, E, T;
inline double solve(double l, double r, int d) {
  double v = (l + r) / 2;
  if (d == K)
    return ((T - E <= v && v < T + E) ? 1.0 : 0.0);
  if (v < T)
    return solve(l, (l + r) / 2, d + 1) * P +
           solve((l + r) / 2, r, d + 1) * (1.0 - P);
  return solve(l, (l + r) / 2, d + 1) * (1.0 - P) +
         solve((l + r) / 2, r, d + 1) * P;
}
int main() {
  cin >> K >> L >> R >> P >> E >> T;
  cout << fixed << setprecision(15) << solve(L, R, 0) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>
using namespace std;
int K, L, R;
double P, E, T;
double solve(double l, double r, int d) {
  double v = (l + r) / 2;
  if (d == K)
    return ((T - E <= v && v < T + E) ? 1.0 : 0.0);
  if (v < T)
    return solve(l, (l + r) / 2, d + 1) * P +
           solve((l + r) / 2, r, d + 1) * (1.0 - P);
  return solve(l, (l + r) / 2, d + 1) * (1.0 - P) +
         solve((l + r) / 2, r, d + 1) * P;
}
int main() {
  cin >> K >> L >> R >> P >> E >> T;
  cout << fixed << setprecision(15) << solve(L, R, 0) << endl;
  return 0;
}