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

#include <cmath>
#include <iostream>
using namespace std;
int dp[20000][256];
signed main() {
  for (int n, m; cin >> n >> m, n;) {
    int c[20000], x[20];
    for (int i = 0; i < n; i++)
      fill(dp[i], dp[i] + 256, (int)1e9);
    for (int i = 0; i < m; i++)
      cin >> x[i];
    for (int i = 0; i < n; i++)
      cin >> c[i];
    for (int i = 0; i < m; i++) {
      int num = 128 + x[i];
      if (num < 0)
        num = 0;
      if (num > 255)
        num = 255;
      dp[0][num] = (int)pow(num - c[0], 2);
    }
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 256; j++) {
        if (dp[i - 1][j] != (int)1e9) {
          for (int k = 0; k < m; k++) {
            int num = j + x[k];
            if (num < 0)
              num = 0;
            if (num > 255)
              num = 255;
            dp[i][num] =
                min(dp[i][num], dp[i - 1][j] + (int)pow(c[i] - num, 2));
          }
        }
      }
    }
    /*
      for(int i=0;i<n;i++){
      for(int j=0;j<256;j++) cout<<(dp[i][j]!=1e9?dp[i][j]:-1)<<" ";
      cout<<endl;
      }*/
    int sm = 1e9;
    for (int i = 0; i < 256; i++)
      sm = min(sm, dp[n - 1][i]);
    cout << sm << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <cmath>
#include <iostream>
#define int long long
using namespace std;
int dp[20000][256];
signed main() {
  for (int n, m; cin >> n >> m, n;) {
    int c[20000], x[20];
    for (int i = 0; i < n; i++)
      fill(dp[i], dp[i] + 256, (int)1e9);
    for (int i = 0; i < m; i++)
      cin >> x[i];
    for (int i = 0; i < n; i++)
      cin >> c[i];
    for (int i = 0; i < m; i++)
      dp[0][x[i] + 128] = (int)pow(x[i] + 128 - c[0], 2);
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 256; j++) {
        if (dp[i - 1][j] != (int)1e9) {
          for (int k = 0; k < m; k++) {
            int num = j + x[k];
            if (num < 0)
              num = 0;
            if (num > 255)
              num = 255;
            dp[i][num] =
                min(dp[i][num], dp[i - 1][j] + (int)pow(c[i] - num, 2));
          }
        }
      }
    }
    /*
      for(int i=0;i<n;i++){
      for(int j=0;j<256;j++) cout<<(dp[i][j]!=1e9?dp[i][j]:-1)<<" ";
      cout<<endl;
      }*/
    int sm = 1e9;
    for (int i = 0; i < 256; i++)
      sm = min(sm, dp[n - 1][i]);
    cout << sm << endl;
  }
  return 0;
}
Problem p01317 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF (1e9)
#define M 1005
#define N 205
using namespace std;
typedef long long ll;

ll n, m, r, z[M], sld[2][N][N];

void init() { rep(i, 2) rep(j, n) rep(k, n) sld[i][j][k] = INF; }

void add_edge(ll sl, ll x, ll y, ll t) {
  sld[sl][x][y] = sld[sl][y][x] = min(sld[sl][x][y], t);
}

void warshall_floyd() {
  rep(sl, 2) rep(k, n) rep(i, n) rep(j, n) sld[sl][i][j] =
      min(sld[sl][i][j], sld[sl][i][k] + sld[sl][k][j]);
  rep(sl, 2) rep(i, n) sld[sl][i][i] = 0;
}

ll dp[M][N];

void solve() {
  rep(i, r) rep(j, n) dp[i][j] = INF;
  dp[0][z[0]] = 0;

  rep(i, r - 1) rep(j, n) {
    if (dp[i][j] == INF)
      continue;
    ll cost = dp[i][j] + sld[0][z[i]][z[i + 1]];
    dp[i + 1][j] = min(dp[i + 1][j], cost);
    rep(k, n) {
      ll cost2 = dp[i][j] + sld[0][z[i]][j];
      cost2 += sld[1][j][k] + sld[0][k][z[i + 1]];
      dp[i + 1][k] = min(dp[i + 1][k], cost2);
    }
  }
  ll ans = INF;
  rep(i, n) ans = min(ans, dp[r - 1][i]);
  cout << ans << endl;
}

int main() {
  while (1) {
    cin >> n >> m;
    if (!n && !m)
      break;
    ll x, y, t;
    char sl;

    init();

    rep(i, m) {
      cin >> x >> y >> t >> sl;
      x--, y--;
      if (sl == 'L')
        add_edge(0, x, y, t);
      else
        add_edge(1, x, y, t);
    }

    warshall_floyd();

    cin >> r;
    rep(i, r) cin >> z[i], z[i]--;

    solve();
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF (1e9)
#define M 1005
#define N 205
using namespace std;
typedef pair<int, char> P;
typedef pair<int, P> P1;
typedef pair<int, int> P2;
typedef pair<P2, P2> P3;

vector<P1> G[N];
int n, m, r, z[M];

int d[N][N][M];

int dijkstra() {
  priority_queue<P3, vector<P3>, greater<P3>> q;

  d[0][0][0] = 0;
  q.push(P3(P2(0, 0), P2(0, 0)));

  while (!q.empty()) {
    P3 t = q.top();
    q.pop();

    int cost = t.first.first;
    int hune = t.first.second;
    int node = t.second.first;
    int Z = t.second.second;

    if (Z == r - 1)
      return cost;
    if (cost > d[hune][node][Z])
      continue;

    rep(i, G[node].size()) {
      int ncost = cost + G[node][i].second.first;
      char sl = G[node][i].second.second;
      int nnode = G[node][i].first;
      int nhune = hune;
      int nZ = Z;

      if (sl == 'S' && hune != node)
        continue;
      if (z[Z + 1] == nnode)
        nZ++;
      if (sl == 'S')
        nhune = nnode;

      if (d[nhune][nnode][nZ] > ncost) {
        d[nhune][nnode][nZ] = ncost;
        q.push(P3(P2(ncost, nhune), P2(nnode, nZ)));
      }
    }
  }

  return INF;
}

int main() {

  while (1) {
    cin >> n >> m;
    if (!n && !m)
      break;

    int x, y, t;
    char sl;

    rep(i, m) {
      cin >> x >> y >> t >> sl;
      G[x - 1].push_back(P1(y - 1, P(t, sl)));
      G[y - 1].push_back(P1(x - 1, P(t, sl)));
    }

    cin >> r;
    rep(i, r) cin >> z[i], z[i]--;

    rep(i, n) rep(j, n) rep(k, M) d[i][j][k] = INF;

    cout << dijkstra() << endl;

    rep(i, n) G[i].clear();
  }
  return 0;
}
Problem p01317 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i <= (k); i++)
#define INF ((int)1 << 28)
#define mk(i, j) make_pair(i, j)

#define N 200
#define M 10000
#define R 1000
int sdst[N][N];
int ldst[N][N];
int dp[R + 1][N];

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    if (!n)
      break;
    rep(i, n) rep(j, n) { sdst[i][j] = ldst[i][j] = i == j ? 0 : INF; }
    rep(i, m) {
      int x, y, t;
      string s;
      cin >> x >> y >> t;
      x--;
      y--;
      cin >> s;
      if (s[0] == 'L') {
        ldst[x][y] = ldst[y][x] = min(ldst[x][y], t);
      } else {
        sdst[x][y] = sdst[y][x] = min(sdst[x][y], t);
      }
    }
    rep(k, n) rep(i, n) rep(j, n) {
      ldst[i][j] = min(ldst[i][j], ldst[i][k] + ldst[k][j]);
      sdst[i][j] = min(sdst[i][j], sdst[i][k] + sdst[k][j]);
    }
    int r, zp;
    cin >> r;
    rep(i, r) rep(j, n) dp[i][j] = INF;
    cin >> zp;
    zp--;
    dp[0][zp] = 0;
    rep(i, r - 1) {
      int z;
      cin >> z;
      z--;
      rep(j, n) rep(k, n) {
        dp[i + 1][k] =
            min(dp[i + 1][k],
                dp[i][j] + (j == k ? ldst[zp][z]
                                   : ldst[zp][j] + sdst[j][k] + ldst[k][z]));
      }
      zp = z;
    }
    int ans = INF;
    rep(i, n) ans = min(dp[r - 1][i], ans);
    cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i <= (k); i++)
#define INF ((int)1 << 29)
#define mk(i, j) make_pair(i, j)

#define N 200
#define M 10000
#define R 1000
int sdst[N][N];
int ldst[N][N];
int dp[R + 1][N];

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    if (!n)
      break;
    rep(i, n) rep(j, n) { sdst[i][j] = ldst[i][j] = i == j ? 0 : INF; }
    rep(i, n) {
      int x, y, t;
      string s;
      cin >> x >> y >> t;
      x--;
      y--;
      cin >> s;
      if (s[0] == 'L') {
        ldst[x][y] = ldst[y][x] = min(ldst[x][y], t);
      } else {
        sdst[x][y] = sdst[y][x] = min(sdst[x][y], t);
      }
      // cout << x << " " << y << " " << t << " " << s << endl;
    }
    rep(k, n) rep(i, n) rep(j, n) {
      ldst[i][j] = min(ldst[i][j], ldst[i][k] + ldst[k][j]);
      sdst[i][j] = min(sdst[i][j], sdst[i][k] + sdst[k][j]);
    }
    int r, zp;
    cin >> r;
    rep(i, r) rep(j, n) dp[i][j] = INF;
    cin >> zp;
    zp--;
    dp[0][zp] = 0;
    rep(i, r - 1) {
      int z;
      cin >> z;
      z--;
      rep(j, n) rep(k, n) {
        dp[i + 1][k] =
            min(dp[i + 1][k],
                dp[i][j] + (j == k ? ldst[zp][z]
                                   : ldst[zp][j] + sdst[j][k] + ldst[k][z]));
      }
      zp = z;
    }
    int ans = INF;
    rep(i, n) ans = min(dp[r - 1][i], ans);
    cout << ans << endl;
  }
}
Problem p01317 (C++) — buggy submission, verdict: Memory Limit Exceeded

// 34
#include <algorithm>
#include <iostream>

using namespace std;

#define INF (1 << 28)

int main() {
  for (int n, m; cin >> n >> m, n | m;) {
    int d[2][201][201];
    fill(d[0][0], d[2][0], INF);
    while (m--) {
      int x, y, t;
      char sl;
      cin >> x >> y >> t >> sl;
      int s = sl == 'L';
      d[s][x][y] = d[s][y][x] = min(d[s][y][x], t);
    }
    for (int i = 0; i < 2; i++) {
      for (int j = 1; j <= n; j++) {
        d[i][j][j] = 0;
      }
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          for (int l = 1; l <= n; l++) {
            d[i][k][l] = min(d[i][k][l], d[i][k][j] + d[i][j][l]);
          }
        }
      }
    }
    int r;
    cin >> r;
    int p[2][201];
    fill(p[0], p[2], INF);
    int s;
    cin >> s;
    p[0][s] = 0;
    for (int i = 0; i < r - 1; i++) {
      int z;
      cin >> z;
      int b = i & 1;
      fill(p[!b], p[!b + 1], INF);
      for (int j = 1; j <= n; j++) {
        p[!b][j] = min(p[!b][j], p[b][j] + d[1][s][z]);
        for (int k = 1; k <= n; k++) {
          p[!b][k] =
              min(p[!b][k], p[b][j] + d[1][s][j] + d[0][j][k] + d[1][k][z]);
        }
      }
      s = z;
    }
    cout << *min_element(p[~r & 1], p[(~r & 1) + 1]) << endl;
  }
  return 0;
}


Error: MLE

Fixed submission:

// 58
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

struct E {
  int d, t;
  bool s;
};

struct S {
  int t, x, p, b;
  bool operator<(S a) const { return t > a.t; }
};

int main() {
  for (int n, m; cin >> n >> m, n | m;) {
    vector<E> e[201];
    int d[201][201];
    fill(d[0], d[201], 1 << 29);
    while (m--) {
      int x, y, t;
      char sl;
      cin >> x >> y >> t >> sl;
      E a = {y, t, sl == 'S'};
      e[x].push_back(a);
      E b = {x, t, sl == 'S'};
      e[y].push_back(b);
      if (sl == 'L') {
        d[x][y] = d[y][x] = min(d[y][x], t);
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
        }
      }
    }
    int r;
    cin >> r;
    int z[1000];
    for (int i = 0; i < r; i++) {
      cin >> z[i];
    }
    priority_queue<S> que;
    S is = {0, 0, z[0], z[0]};
    que.push(is);
    int p[201][201] = {{}};
    fill(p[0], p[201], false);
    for (;;) {
      S c = que.top();
      if (c.x == r - 1)
        break;
      que.pop();
      if (p[c.p][c.b] >= c.x + 1)
        continue;
      p[c.p][c.b] = c.x + 1;
      if (c.p != c.b && d[c.p][z[c.x + 1]] == 1 << 29) {
        S n = {c.t + d[c.p][c.b], c.x, c.b, c.b};
        que.push(n);
      } else {
        for (int i = 0; i < e[c.p].size(); i++) {
          E ce = e[c.p][i];
          if (!ce.s || c.b == c.p) {
            S n = {c.t + ce.t, c.x + (ce.d == z[c.x + 1]), ce.d,
                   ce.s ? ce.d : c.b};
            if (p[n.p][n.b] < n.x + 1) {
              que.push(n);
            }
          }
        }
      }
    }
    cout << que.top().t << endl;
  }
  return 0;
}
Problem p01317 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define r(i, n) for (int i = 0; i < n; i++)
int v1[203][203], v2[203][203], a1, a2, a3, n, m;
int dp[2][203][203], t, x, pre;
char c;
int main() {
  while (cin >> n >> m, n) {
    int ans = 1e8;
    r(i, 2) r(j, 203) r(k, 203) dp[i][j][k] = 1e8;
    r(i, 203) r(j, 203) v1[i][j] = v2[j][i] = (i == j ? 0 : 1e8);
    r(i, m) {
      cin >> a1 >> a2 >> a3 >> c;
      a1--, a2--;
      if (c == 'L')
        v1[a1][a2] = v1[a2][a1] = a3;
      else
        v2[a1][a2] = v2[a2][a1] = a3;
    }
    r(k, n) r(i, n) r(j, n) {
      v1[i][j] = min(v1[i][j], v1[i][k] + v1[k][j]);
      v2[i][j] = min(v2[i][j], v2[i][k] + v2[k][j]);
    }
    cin >> t >> pre;
    pre--;
    dp[0][pre][pre] = 0;
    for (int k = 0; k < t - 1; k++) {
      cin >> x;
      x--;
      for (int i = 0; i < n; i++) {
        dp[(k + 1) % 2][x][i] =
            min(dp[(k + 1) % 2][x][i], dp[k % 2][pre][i] + v1[pre][x]);
        for (int j = 0; j < n; j++) {
          dp[(k + 1) % 2][x][j] =
              min(dp[(k + 1) % 2][x][j],
                  dp[k % 2][pre][i] + v1[pre][i] + v2[i][j] + v1[j][x]);
        }
      }
      r(i, 203) r(j, 203) dp[k % 2][i][j] = 1e8;
      pre = x;
    }
    r(i, 203) ans = min(ans, dp[(t - 1) % 2][pre][i]);
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define r(i, n) for (int i = 0; i < n; i++)
int v1[203][203], v2[203][203], a1, a2, a3, n, m;
int dp[2][203][203], t, x, pre;
char c;
int main() {
  while (cin >> n >> m, n) {
    int ans = 1e8;
    r(i, 2) r(j, 203) r(k, 203) dp[i][j][k] = 1e8;
    r(i, 203) r(j, 203) v1[i][j] = v2[j][i] = (i == j ? 0 : 1e8);
    r(i, n) {
      cin >> a1 >> a2 >> a3 >> c;
      a1--, a2--;
      if (c == 'L')
        v1[a1][a2] = v1[a2][a1] = a3;
      else
        v2[a1][a2] = v2[a2][a1] = a3;
    }
    r(k, n) r(i, n) r(j, n) {
      v1[i][j] = min(v1[i][j], v1[i][k] + v1[k][j]);
      v2[i][j] = min(v2[i][j], v2[i][k] + v2[k][j]);
    }
    cin >> t >> pre;
    pre--;
    dp[0][pre][pre] = 0;
    for (int k = 0; k < t - 1; k++) {
      cin >> x;
      x--;
      for (int i = 0; i < n; i++) {
        dp[(k + 1) % 2][x][i] =
            min(dp[(k + 1) % 2][x][i], dp[k % 2][pre][i] + v1[pre][x]);
        for (int j = 0; j < n; j++) {
          dp[(k + 1) % 2][x][j] =
              min(dp[(k + 1) % 2][x][j],
                  dp[k % 2][pre][i] + v1[pre][i] + v2[i][j] + v1[j][x]);
        }
      }
      r(i, 203) r(j, 203) dp[k % 2][i][j] = 1e8;
      pre = x;
    }
    r(i, 203) ans = min(ans, dp[(t - 1) % 2][pre][i]);
    cout << ans << endl;
  }
}
Problem p01317 (C++) — buggy submission, verdict: Runtime Error

// AOJ 2200 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2200)
#include <algorithm>
#include <cstdio>
#include <limits>
#include <queue>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); ++i)

const int MAX_N = 200, MAX_R = 1000, INF = std::numeric_limits<int>::max() >> 4;

int N, M, R;
int land[MAX_N][MAX_N], sea[MAX_N][MAX_N];
int dp[MAX_R + 1][MAX_N];
int z[MAX_R];

int main() {
  while (scanf("%d%d", &N, &M), N | M) {
    rep(i, N) rep(j, N) land[i][j] = sea[i][j] = i == j ? 0 : INF;

    rep(i, M) {
      int x, y, t;
      char sl[2];

      scanf("%d%d%d%s", &x, &y, &t, sl);
      --x;
      --y;

      auto mat = *sl == 'L' ? land : sea;
      mat[x][y] = mat[y][x] = std::min(mat[x][y], t);
    }

    scanf("%d", &R);
    rep(i, R) scanf("%d", z + i), --z[i];

    rep(k, N) rep(i, N) rep(j, N) {
      land[i][j] = std::min(land[i][j], land[i][k] + land[k][j]);
      sea[i][j] = std::min(sea[i][j], sea[i][k] + sea[k][j]);
    }

    rep(i, R + 1) rep(j, N + 1) dp[i][j] = INF;

    dp[0][z[0]] = 0;
    rep(i, R - 1) rep(j, N) rep(k, N) {
      if (j != k)
        dp[i + 1][j] =
            std::min(dp[i + 1][j],
                     dp[i][k] + land[z[i]][k] + sea[k][j] + land[j][z[i + 1]]);
      else
        dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + land[z[i]][z[i + 1]]);
    }

    printf("%d\\n", *std::min_element(dp[R - 1], dp[R - 1] + N));
  }

  return 0;
}

Error: 0

Fixed submission:

// AOJ 2200 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2200)
#include <algorithm>
#include <cstdio>
#include <limits>
#include <queue>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); ++i)

const int MAX_N = 200, MAX_R = 1000, INF = std::numeric_limits<int>::max() >> 4;

int N, M, R;
int land[MAX_N][MAX_N], sea[MAX_N][MAX_N];
int dp[MAX_R + 1][MAX_N];
int z[MAX_N];

int main() {
  while (scanf("%d%d", &N, &M), N | M) {
    rep(i, N) rep(j, N) land[i][j] = sea[i][j] = i == j ? 0 : INF;

    rep(i, M) {
      int x, y, t;
      char sl[2];

      scanf("%d%d%d%s", &x, &y, &t, sl);
      --x;
      --y;

      auto mat = *sl == 'L' ? land : sea;
      mat[x][y] = mat[y][x] = std::min(mat[x][y], t);
    }

    scanf("%d", &R);
    rep(i, R) scanf("%d", z + i), --z[i];

    rep(k, N) rep(i, N) rep(j, N) {
      land[i][j] = std::min(land[i][j], land[i][k] + land[k][j]);
      sea[i][j] = std::min(sea[i][j], sea[i][k] + sea[k][j]);
    }

    rep(i, R + 1) rep(j, N + 1) dp[i][j] = INF;

    dp[0][z[0]] = 0;
    rep(i, R - 1) rep(j, N) rep(k, N) {
      if (j != k)
        dp[i + 1][j] =
            std::min(dp[i + 1][j],
                     dp[i][k] + land[z[i]][k] + sea[k][j] + land[j][z[i + 1]]);
      else
        dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + land[z[i]][z[i + 1]]);
    }

    printf("%d\\n", *std::min_element(dp[R - 1], dp[R - 1] + N));
  }

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

#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define INF 10000000
int mini(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
int maxim(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

int main() {
  while (1) {
    int i, j, n, s, t, max = 0, min = 500;
    cin >> n;
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      t = 0;
      for (j = 0; j < 5; j++) {
        cin >> s;
        t += s;
      }
      max = maxim(max, t);
      min = mini(min, t);
    }
    cout << max << ' ' << min << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define INF 10000000
int mini(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
int maxim(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

int main() {
  while (1) {
    int i, j, n, s, t, max = 0, min = 500;
    cin >> n;
    for (i = 0; i < n; i++) {
      t = 0;
      for (j = 0; j < 5; j++) {
        cin >> s;
        t += s;
      }
      max = maxim(max, t);
      min = mini(min, t);
    }
    cout << max << ' ' << min << endl;
  }
  return 0;
}
Problem p01321 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 1 << 29
using namespace std;

int main() {
  int a, b;
  while (scanf("%d", &a), a) {
    int MIN = 1 << 29, MAX = -(1 << 29);
    for (int c = 0; c < a; c++) {
      int s = 0;
      int e;
      for (int d = 0; d < 5; d++) {
        scanf("%d", &e);
        s += e;
      }
      MIN = min(MIN, s);
      MAX = max(MAX, s);
    }
    printf("%d %d\\n", MAX, MIN);
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define INF 1 << 29
using namespace std;

int main() {
  int a, b;
  while (scanf("%d%d", &a), a) {
    int MIN = 1 << 29, MAX = -(1 << 29);
    for (int c = 0; c < a; c++) {
      int s = 0;
      int e;
      for (int d = 0; d < 5; d++) {
        scanf("%d", &e);
        s += e;
      }
      MIN = min(MIN, s);
      MAX = max(MAX, s);
    }
    printf("%d %d\\n", MAX, MIN);
  }
}
Problem p01322 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

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

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

bool check(string s, string a) {
  rep(i, a.size()) {
    if (a[i] == '*')
      s[i] = '*';
  }
  if (a == s)
    return true;
  else
    return false;
}

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0)
      break;
    string hit[200] = {};
    int v[200] = {};
    rep(i, n) {
      cin >> hit[i];
      cin >> v[i];
    }

    string mine[2000] = {};
    rep(i, m) cin >> mine[i];

    ll sum = 0;
    rep(i, m) {
      rep(j, n) {
        if (check(mine[i], hit[j])) {
          sum += v[j];
          break;
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

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

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

bool check(string a, string s) {
  rep(i, a.size()) {
    if (a[i] == '*')
      s[i] = '*';
  }
  if (a == s)
    return true;
  else
    return false;
}

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    string hit[200] = {};
    int v[200] = {};
    rep(i, n) {
      cin >> hit[i];
      cin >> v[i];
    }

    string mine[2000] = {};
    rep(i, m) cin >> mine[i];

    ll sum = 0;
    rep(i, n) {
      rep(j, m) {
        if (check(hit[j], mine[i])) {
          sum += v[j];
          break;
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p01322 (C++) — buggy submission, verdict: Runtime Error

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

bool check(string a, string b) {
  for (int i = 0; i < 8; i++) {
    if (a[i] == '*')
      continue;
    if (a[i] != b[i])
      return 0;
  }
  return 1;
}

int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (!n && !m)
      break;
    string a[101], b[1001];
    int mon[1001];
    ;
    for (int i = 0; i < n; i++)
      cin >> a[i] >> mon[i];
    for (int i = 0; i < m; i++)
      cin >> b[i];

    long long ans = 0;
    for (int i = 0; i < m; i++)
      for (int j = 0; j < n; j++)
        if (check(a[j], b[i]))
          ans += mon[j];
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

bool check(string a, string b) {
  for (int i = 0; i < 8; i++) {
    if (a[i] == '*')
      continue;
    if (a[i] != b[i])
      return 0;
  }
  return 1;
}

int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (!n && !m)
      break;
    string a[101], b[101];
    int mon[101];
    ;
    for (int i = 0; i < n; i++)
      cin >> a[i] >> mon[i];
    for (int i = 0; i < m; i++)
      cin >> b[i];

    long long ans = 0;
    for (int i = 0; i < m; i++)
      for (int j = 0; j < n; j++)
        if (check(a[j], b[i]))
          ans += mon[j];
    cout << ans << endl;
  }

  return 0;
}