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

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

const int MAX_C = 16;
const int MAX_D = 31;
const int MAX_W = 51;
const int MAX_X = 6;
const int INF = 1 << 28;
int C, D, W, X;
int E[MAX_C][MAX_D], F[MAX_C][MAX_D];
int T[MAX_D][MAX_W][MAX_X];

int main() {
  while (cin >> C >> D >> W >> X && (C | D | W | X)) {
    for (int i = 1; i <= C; ++i)
      for (int j = 1; j <= D; ++j)
        cin >> E[i][j];
    for (int i = 1; i <= C; ++i) {
      for (int j = 1; j <= D; ++j) {
        cin >> F[i][j];
        if (E[i][j] == 0)
          F[i][j] = W * 2;
      }
    }

    for (int j = 1; j <= D; ++j) {
      E[0][j] = F[0][j] = 0;
      for (int i = 1; i <= C; ++i) {
        E[i][j] = E[i][j] + E[i - 1][j];
        F[i][j] = F[i][j] + F[i - 1][j];
      }
    }

    fill(T[0][0], T[MAX_D][0], 0);
    T[0][0][0] = 0;
    int ans = 0;
    for (int i = 1; i <= D; ++i) {
      for (int k = 0; k <= X; ++k) {
        for (int p = 0; p < C; ++p) {
          for (int q = p + 1; q <= C; ++q) {
            int pk = k - (q - p >= 2);
            if (pk < 0)
              break;
            int value = E[q][i] - E[p][i];
            int cost = F[q][i] - F[p][i];
            for (int j = cost; j <= W; ++j) {
              T[i][j][k] = max(max(T[i][j][k], T[i - 1][j][k]),
                               T[i - 1][j - cost][pk] + value);
              ans = max(ans, T[i][j][k]);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

const int MAX_C = 17;
const int MAX_D = 32;
const int MAX_W = 52;
const int MAX_X = 7;
const int INF = 1 << 28;
int C, D, W, X;
int E[MAX_C][MAX_D], F[MAX_C][MAX_D];
int T[MAX_D][MAX_W][MAX_X];

int main() {
  while (cin >> C >> D >> W >> X && (C | D | W | X)) {
    for (int i = 1; i <= C; ++i)
      for (int j = 1; j <= D; ++j)
        cin >> E[i][j];
    for (int i = 1; i <= C; ++i) {
      for (int j = 1; j <= D; ++j) {
        cin >> F[i][j];
        if (F[i][j] == 0)
          F[i][j] = INF;
      }
    }

    for (int j = 1; j <= D; ++j) {
      E[0][j] = F[0][j] = 0;
      for (int i = 1; i <= C; ++i) {
        E[i][j] = E[i][j] + E[i - 1][j];
        F[i][j] = F[i][j] + F[i - 1][j];
      }
    }

    fill(T[0][0], T[MAX_D][0], 0);
    T[0][0][0] = 0;
    int ans = 0;
    for (int i = 1; i <= D; ++i) {
      for (int k = 0; k <= X; ++k) {
        for (int p = 0; p < C; ++p) {
          for (int q = p + 1; q <= C; ++q) {
            int pk = k - (q - p >= 2);
            if (pk < 0)
              break;
            int value = E[q][i] - E[p][i];
            int cost = F[q][i] - F[p][i];
            for (int j = cost; j <= W; ++j) {
              T[i][j][k] = max(T[i][j][k], T[i - 1][j - cost][pk] + value);
              ans = max(ans, T[i][j][k]);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00676 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {

  int a, l, x, i = 0;
  double M[100000], c, d, e, f;

  while (scanf("%d%d%d", &a, &l, &x) != EOF) {

    c = (double)((2 * x * l) + (x * x)) / 4;
    e = l * l - (double)(a * a) / 4;
    d = sqrt(c);
    f = sqrt(e);
    M[i] = ((double)a / 2) * f + l * d;

    i++;
  }

  for (int j = 0; j < i; j++) {
    printf("%.10f\\n", M[j]);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {

  int a, l, x, i = 0;
  double M[1000], c, d, e, f;

  while (scanf("%d%d%d", &a, &l, &x) != EOF) {

    c = (double)((2 * x * l) + (x * x)) / 4;
    e = l * l - (double)(a * a) / 4;
    d = sqrt(c);
    f = sqrt(e);
    M[i] = ((double)a / 2) * f + l * d;

    i++;
  }

  for (int j = 0; j < i; j++) {
    printf("%.10f\\n", M[j]);
  }

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

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

int main() {
  double a, l, x;
  while (~scanf("%lf%lf%lf", &a, &l, &x)) {
    double s1 = (a + l + l) / 2, s2 = (l + l + x) / 2;
    double d = (l + x) / 2;
    printf("%.10lf\\n", sqrt(s1 * (s1 - a) * (s1 - l) * (s1 - l)) +
                           sqrt(s2 * (s2 - d) * (s2 - d) * (s2 - l)) * 2);
  }
}

Error: TLE

Fixed submission:

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

int main() {
  double a, l, x;
  while (~scanf("%lf%lf%lf", &a, &l, &x), a) {
    double s1 = (a + l + l) / 2, s2 = (l + l + x) / 2;
    double d = (l + x) / 2;
    printf("%.10lf\\n", sqrt(s1 * (s1 - a) * (s1 - l) * (s1 - l)) +
                           sqrt(s2 * (s2 - d) * (s2 - d) * (s2 - l)) * 2);
  }
}
Problem p00676 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

static const double EPS = 1e-8;

int main() {
  double a, l, x;

  while (~scanf("%lf %lf %lf", &a, &l, &x)) {
    double s = (a + l + l) / 2.0;
    double ca = sqrt(s * (s - a) * (s - l) * (s - l));

    double res = 0.0;

    for (double scale = 0.00001; scale < 1.0; scale += 0.00001) {
      double e1 = scale * (l + x);
      double e2 = (1.0 - scale) * (l + x);

      double s2 = (e1 + e2 + l) / 2.0;
      if (s2 * (s2 - e1) * (s2 - e2) * (s2 - l) < 0)
        continue;

      double ca2 = sqrt(s2 * (s2 - e1) * (s2 - e2) * (s2 - l));

      res = max(ca + ca2 + ca2, res);
    }

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

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

static const double EPS = 1e-8;

int main() {
  double a, l, x;

  while (~scanf("%lf %lf %lf", &a, &l, &x)) {
    double s = (a + l + l) / 2.0;
    double ca = sqrt(s * (s - a) * (s - l) * (s - l));

    double res = 0.0;

    for (double scale = 0.000001; scale < 1.0; scale += 0.000001) {
      double e1 = scale * (l + x);
      double e2 = (1.0 - scale) * (l + x);

      double s2 = (e1 + e2 + l) / 2.0;
      if (s2 * (s2 - e1) * (s2 - e2) * (s2 - l) < 0)
        continue;

      double ca2 = sqrt(s2 * (s2 - e1) * (s2 - e2) * (s2 - l));

      res = max(ca + ca2 + ca2, res);
    }

    printf("%lf\\n", res);
  }
}
Problem p00676 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

double calc(double a, double b, double c) {
  double s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}

void func(double a, double l, double x) {

  double tmp = (l + x) / 2;

  printf("%.10lf\\n", calc(a, l, l) + calc(tmp, tmp, l) * 2);
}

int main() {

  double a, l, x;

  while (scanf("%lf %lf %lf", &a, &l, &x) != EOF) {
    func(a, l, x);
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

double calc(double a, double b, double c) {
  double s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}

void func(double a, double l, double x) {

  double tmp = (l + x) / 2;

  printf("%.10lf\\n", calc(a, l, l) + calc(tmp, tmp, l) * 2);
}

int main() {

  double a, l, x;

  while (scanf("%lf %lf %lf", a, l, x) != EOF) {
    func(a, l, x);
  }
}
Problem p00677 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int, int> P;

int main() {
  int n, d, m;
  while (cin >> n >> d >> m) {
    vector<P> S[110];

    for (int i = 0, k; i < n; i++) {
      cin >> k;
      S[i].resize(k);
      for (int j = 0; j < k; j++)
        cin >> S[i][j].f >> S[i][j].s;
    }

    int dp[1000] = {};
    for (int i = 0, I; i < d; i++) {
      cin >> I;
      for (int j = 0; j < S[I].size(); j++)
        for (int k = m; k >= 0; k--) {
          if (k - S[I][j].s < 0)
            break;
          dp[k] = max(dp[k - S[I][j].s] + S[I][j].f, dp[k]);
        }
    }

    int cost = 0, ans = 0;
    for (int j = 0; j <= m; j++)
      if (ans < dp[j])
        ans = dp[j], cost = j;
    cout << ans << " " << cost << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int, int> P;

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

    vector<P> S[101];
    for (int i = 0, k; i < n; i++) {
      cin >> k;
      S[i].resize(k);
      for (int j = 0; j < k; j++)
        cin >> S[i][j].f >> S[i][j].s;
    }
    int f[101];
    for (int i = 0; i < d; i++)
      cin >> f[i];

    int dp[101][1000] = {};
    for (int i = 0; i < d; i++) {
      int I = f[i];
      for (int j = 0; j < S[I].size(); j++)
        for (int k = 0; k + S[I][j].s <= m; k++)
          dp[i + 1][k + S[I][j].s] =
              max(dp[i + 1][k + S[I][j].s], dp[i][k] + S[I][j].f);
    }

    int cost = 0, ans = 0;
    for (int j = 0; j <= m; j++)
      if (ans < dp[d][j])
        ans = dp[d][j], cost = j;
    cout << ans << " " << cost << endl;
  }
  return 0;
}
Problem p00677 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef pair<int, int> pii;

int dp1[101][301], dp2[101][301];

int main(void) {

  int s, d, m;
  while (cin >> s >> d >> m) {
    vector<pii> a[s];
    for (int i = 0; i < s; i++) {
      int w, p, k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        cin >> w >> p;
        a[i].push_back(pii(p, w));
      }
    }

    vector<int> f(d);
    for (int i = 0; i < d; i++)
      cin >> f[i];

    fill(dp1[0], dp1[101], 0);

    for (int i = 0; i < s; i++) {
      for (int j = 0; j < a[i].size(); j++) {
        for (int k = 300; k >= 0; k--) {
          if (k + a[i][j].first <= 300) {
            dp1[i][k + a[i][j].first] =
                max(dp1[i][k + a[i][j].first], dp1[i][k] + a[i][j].second);
          }
        }
      }
    }

    fill(dp2[0], dp2[101], 0);
    for (int i = 0; i < d; i++) {
      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= m; k++) {
          if (j + k <= 300)
            dp2[i + 1][j + k] =
                max(dp2[i + 1][j + k], dp2[i][j] + dp1[f[i]][k]);
        }
      }
    }

    int minp = (1 << 29), maxw = -1;
    for (int j = 0; j <= m; j++) {
      for (int i = 0; i <= d; i++) {
        if (maxw < dp2[i][j]) {
          maxw = dp2[i][j];
          minp = j;
        }
      }
    }

    cout << maxw << " " << minp << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

typedef pair<int, int> pii;

int dp1[50][301], dp2[101][301];

int main(void) {

  int s, d, m;
  while (cin >> s >> d >> m) {
    vector<pii> a[s];
    for (int i = 0; i < s; i++) {
      int w, p, k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        cin >> w >> p;
        a[i].push_back(pii(p, w));
      }
    }

    vector<int> f(d);
    for (int i = 0; i < d; i++)
      cin >> f[i];

    fill(dp1[0], dp1[50], 0);

    for (int i = 0; i < s; i++) {
      for (int j = 0; j < a[i].size(); j++) {
        for (int k = 300; k >= 0; k--) {
          if (k + a[i][j].first <= 300) {
            dp1[i][k + a[i][j].first] =
                max(dp1[i][k + a[i][j].first], dp1[i][k] + a[i][j].second);
          }
        }
      }
    }

    fill(dp2[0], dp2[101], 0);
    for (int i = 0; i < d; i++) {
      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= m; k++) {
          if (j + k <= 300)
            dp2[i + 1][j + k] =
                max(dp2[i + 1][j + k], dp2[i][j] + dp1[f[i]][k]);
        }
      }
    }

    int minp = (1 << 29), maxw = 0;
    for (int j = 0; j <= m; j++) {
      for (int i = 0; i <= d; i++) {
        if (maxw < dp2[i][j]) {
          maxw = dp2[i][j];
          minp = j;
        }
      }
    }

    cout << maxw << " " << minp << endl;
  }

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

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

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

using namespace std;

void knapsack(int yosan, const vector<pair<int, int>> &a) {
  int n = a.size();
  int dp[301] = {};
  rep(i, n) {
    int value = a[i].first, price = a[i].second;
    for (int j = yosan; j >= price; j--)
      dp[j] = max(dp[j], dp[j - price] + value);
  }
  int ans = max_element(dp, dp + yosan + 1) - dp;
  printf("%d %d\\n", dp[ans], ans);
}

int main() {
  for (int n, days, yosan; ~scanf("%d%d%d", &n, &days, &yosan);) {
    vector<pair<int, int>> kanmi[100];
    rep(i, n) {
      int m;
      scanf("%d", &m);
      kanmi[i].resize(m);
      rep(j, m) scanf("%d%d", &kanmi[i][j].first, &kanmi[i][j].second);
    }

    vector<pair<int, int>> item;
    rep(t, days) {
      int id;
      scanf("%d", &id);
      item.insert(item.end(), kanmi[id].begin(), kanmi[id].end());
    }

    knapsack(yosan, item);
  }

  return 0;
}

Error: 0

Fixed submission:

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

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

using namespace std;

void knapsack(int yosan, const vector<pair<int, int>> &a) {
  int n = a.size();
  int dp[101] = {};
  rep(i, n) {
    int value = a[i].first, price = a[i].second;
    for (int j = yosan; j >= price; j--)
      dp[j] = max(dp[j], dp[j - price] + value);
  }
  int ans = max_element(dp, dp + yosan + 1) - dp;
  printf("%d %d\\n", dp[ans], ans);
}

int main() {
  for (int n, days, yosan; ~scanf("%d%d%d", &n, &days, &yosan);) {
    vector<pair<int, int>> kanmi[100];
    rep(i, n) {
      int m;
      scanf("%d", &m);
      kanmi[i].resize(m);
      rep(j, m) scanf("%d%d", &kanmi[i][j].first, &kanmi[i][j].second);
    }

    vector<pair<int, int>> item;
    rep(t, days) {
      int id;
      scanf("%d", &id);
      item.insert(item.end(), kanmi[id].begin(), kanmi[id].end());
    }

    knapsack(yosan, item);
  }

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

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

using namespace std;

double EPS = 1e-10;

double add(double a, double b) {
  if (abs(a + b) < EPS * (abs(a) + abs(b)))
    return 0;
  return a + b;
}

struct point {
  double x, y;
  point() {}
  point(double x, double y) : x(x), y(y) {}
  point operator+(point p) { return point(add(x, p.x), add(y, p.y)); }
  point operator-(point p) { return point(add(x, -p.x), add(y, -p.y)); }
  point operator*(double d) { return point(x * d, y * d); }
  point operator/(double d) { return point(x / d, y / d); }
};

double dist(point a, point b) {
  return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}

int main(void) {
  int n, x, y, v;
  vector<point> P;
  vector<double> V;

  while (cin >> n, n) {
    P.clear();
    V.clear();

    for (int i = 0; i < n; i++) {
      cin >> x >> y >> v;
      P.push_back(point(x, y));
      V.push_back(v);
    }

    double r = 0.999;
    point now(0, 0);

    for (double d = 10; d > EPS; d *= r) {
      int mx = 0;
      double mxd = 0;

      for (int j = 0; j < P.size(); j++) {
        if (dist(now, P[j]) / V[j] > mxd)
          mx = j, mxd = dist(now, P[j]) / V[j];
      }

      now = now + ((P[mx] - now) / dist(P[mx], now) * d);
    }

    double ans = 0;
    for (int i = 0; i < P.size(); i++) {
      ans = max(ans, dist(now, P[i]) / V[i]);
    }
    printf("%.8f\\n", ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

double EPS = 1e-10;

double add(double a, double b) {
  if (abs(a + b) < EPS * (abs(a) + abs(b)))
    return 0;
  return a + b;
}

struct point {
  double x, y;
  point() {}
  point(double x, double y) : x(x), y(y) {}
  point operator+(point p) { return point(add(x, p.x), add(y, p.y)); }
  point operator-(point p) { return point(add(x, -p.x), add(y, -p.y)); }
  point operator*(double d) { return point(x * d, y * d); }
  point operator/(double d) { return point(x / d, y / d); }
};

double dist(point a, point b) {
  return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}

int main(void) {
  int n, x, y, v;
  vector<point> P;
  vector<double> V;

  while (cin >> n, n) {
    P.clear();
    V.clear();

    for (int i = 0; i < n; i++) {
      cin >> x >> y >> v;
      P.push_back(point(x, y));
      V.push_back(v);
    }

    double r = 0.99999;
    point now(0, 0);

    for (double d = 10; d > EPS; d *= r) {
      int mx = 0;
      double mxd = 0;

      for (int j = 0; j < P.size(); j++) {
        if (dist(now, P[j]) / V[j] > mxd)
          mx = j, mxd = dist(now, P[j]) / V[j];
      }

      now = now + ((P[mx] - now) / dist(P[mx], now) * d);
    }

    double ans = 0;
    for (int i = 0; i < P.size(); i++) {
      ans = max(ans, dist(now, P[i]) / V[i]);
    }
    printf("%.8f\\n", ans);
  }

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

#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int x[110];
int y[110];
int v[110];
int main() {
  int a;
  while (scanf("%d", &a), a) {
    for (int i = 0; i < a; i++) {
      scanf("%d%d%d", x + i, y + i, v + i);
    }
    double ret = 999999999;
    // for(int T=0;T<100;T++){
    double tx = rand() % 101;
    double ty = rand() % 101;
    double mv = 10;
    for (int i = 0; i < 10000; i++) {
      double val = 0;
      int at = 0;
      for (int j = 0; j < a; j++) {
        double dis =
            sqrt((tx - x[j]) * (tx - x[j]) + (ty - y[j]) * (ty - y[j])) / v[j];
        if (val < dis) {
          val = dis;
          at = j;
        }
      }
      ret = min(ret, val);
      double dx = ((double)x[at] - tx) * mv / val;
      double dy = ((double)y[at] - ty) * mv / val;
      tx += dx;
      ty += dy;
      if (i % 200 == 0)
        mv /= 2;
    }
    //}
    printf("%.12f\\n", ret);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int x[110];
int y[110];
int v[110];
int main() {
  int a;
  while (scanf("%d", &a), a) {
    for (int i = 0; i < a; i++) {
      scanf("%d%d%d", x + i, y + i, v + i);
    }
    double ret = 999999999;
    for (int T = 0; T < 100; T++) {
      double tx = rand() % 101;
      double ty = rand() % 101;
      double mv = 10;
      for (int i = 0; i < 10000; i++) {
        double val = 0;
        int at = 0;
        for (int j = 0; j < a; j++) {
          double dis =
              sqrt((tx - x[j]) * (tx - x[j]) + (ty - y[j]) * (ty - y[j])) /
              v[j];
          if (val < dis) {
            val = dis;
            at = j;
          }
        }
        ret = min(ret, val);
        double dx = ((double)x[at] - tx) * mv / val;
        double dy = ((double)y[at] - ty) * mv / val;
        tx += dx;
        ty += dy;
        if (i % 200 == 0)
          mv /= 2;
      }
    }
    printf("%.12f\\n", ret);
  }
}
Problem p00682 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int n, cnt = 1;
  scanf("%d", &n);
  while (n) {
    float s = 0, x0, y0, xa, xb, ya, yb;
    scanf("%f %f", &x0, &y0);
    xb = x0;
    yb = y0;
    for (int i = n - 1; i > 0; i--) {
      xa = xb;
      ya = yb;
      scanf("%f %f", &xb, &yb);
      s += (xb + xa) * (yb - ya);
    }
    s += (x0 + xb) * (y0 - yb);
    printf("%d %.1f\\n", cnt++, s > 0 ? s / 2 : (-s) / 2);
    scanf("%d", &n);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int n, cnt = 1;
  scanf("%d", &n);
  while (n) {
    float s = 0, x0, x1, y0, y1, xa, xb, xc, ya, yb, yc;
    scanf("%d %d", x0, y0);
    xa = x0;
    ya = y0;
    scanf("%d %d", x1, y1);
    xb = x1;
    yb = y1;
    for (int i = n - 2; i > 0; i--) {
      scanf("%d %d", &xc, &yc);
      s += (xb - xa) * (yc - yb) - (xc - xb) * (yb - ya);
      xa = xb;
      ya = yb;
      xb = xc;
      yb = yc;
    }
    s += (xc - xb) * (y0 - yc) - (x0 - xc) * (xc - yb);
    s += (x0 - xc) * (y1 - y0) - (x1 - x0) * (x0 - yc);
    printf("%d %.1f\\n", cnt++, s > 0 ? s : -s);
    scanf("%d", &n);
  }
}
Problem p00682 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>

using namespace std;

typedef complex<double> xy_t;

double dot_product(xy_t a, xy_t b) { return (conj(a) * b).real(); }

double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); }

int main() {

  int counter = 0;
  while (true) {
    counter++;
    xy_t P[100];

    int n;

    cin >> n;

    if (n == 0)
      break;

    for (int i = 0; i < n; i++) {
      double x, y;
      cin >> x >> y;
      P[i] = xy_t(x, y);
    }

    // center all coordinates based on first element
    for (int i = 1; i < n; i++) {
      P[i] -= P[0];
    }

    // calculate sum
    double sum = 0.0;
    for (int i = 1; i + 1 < n; i++) {
      xy_t a = P[i], b = P[i + 1];
      sum += cross_product(a, b) / 2.0;
    }

    printf("%d %.1f\\n", counter, abs(sum));
  }
}

Error: WA

Fixed submission:

#include <cmath>
#include <complex.h>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

typedef complex<double> xy_t;

double dot_product(xy_t a, xy_t b) { return (conj(a) * b).real(); }

double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); }

double triangle_area(xy_t a, xy_t b) { return (cross_product(a, b) / 2.0); }

int main() {
  xy_t P[110];
  int N = 0;
  double x, y;

  while (scanf("%lf,%lf", &x, &y) != EOF) {
    xy_t entry(x, y);
    P[N++] = entry;
  }

  // center all coordinates based on first element
  for (int i = 1; i < N; i++) {
    P[i] -= P[0];
  }

  // calculate sum
  double sum = 0.0;
  for (int i = 1; i + 1 < N; i++) {
    xy_t b = P[i], c = P[i + 1];
    sum += triangle_area(b, c);
  }

  printf("%.6f\\n", abs(sum));
}