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

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

#define INF 100000000

using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int V, match[1001];
bool used[1001];
vector<int> G[1001];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  fill(match, match + 1001, -1);
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      fill(used, used + 1001, false);
      if (dfs(v))
        res++;
    }
  }
  return res;
}

int main(void) {

  int m, n;

  while (cin >> m >> n, m | n) {
    vector<int> b(m), r(n);
    for (int i = 0; i < 1001; i++)
      G[i].clear();

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

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (gcd(b[i], r[j]) != 1)
          add_edge(i, j + m);
      }
    }
    V = max(m, n);
    cout << bipartite_matching() << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

#define INF 100000000

using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int V, match[501];
bool used[501];
vector<int> G[501];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  fill(match, match + 501, -1);
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      fill(used, used + 501, false);
      if (dfs(v))
        res++;
    }
  }
  return res;
}

int main(void) {

  int m, n;

  while (cin >> m >> n, m | n) {
    vector<int> b(m), r(n);
    for (int i = 0; i < 501; i++)
      G[i].clear();

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

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (gcd(b[i], r[j]) != 1)
          add_edge(i, j + m);
      }
    }
    V = max(m, n);
    cout << bipartite_matching() << endl;
  }

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

#include <iostream>
using namespace std;

int m, n;
int blue[505];
int red[505];

bool bluematch[505];
int redpair[505];

int path[505][505];

int gcd(int a, int b) {
  int m;

  while (1) {
    m = a % b;
    if (m == 0)
      return b;
    a = b;
    b = m;
  }
  return 1;
}

bool match(int x) {
  if (x < 0)
    return true;

  if (bluematch[x]) {
    return false;
  }
  bluematch[x] = true;

  for (int y = 0; y < n; y++) {
    if (!path[x][y])
      continue;
    if (match(redpair[y])) {
      redpair[y] = x;
      return true;
    }
  }

  return false;
}

int main() {
  ios_base::sync_with_stdio(0);

  int i, j, cnt;
  while (1) {
    cin >> m >> n;
    if (m == 0)
      return 0;

    for (i = 0; i < m; i++) {
      cin >> blue[i];
    }

    for (i = 0; i < n; i++) {
      cin >> red[i];
    }

    for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++) {
        if (gcd(blue[i], red[j]) != 1) {
          path[i][j] = 1;
        } else {
          path[i][j] = 0;
        }
      }
    }

    fill(redpair, redpair + n, -1);
    cnt = 0;
    for (i = 0; i < m; i++) {
      fill(bluematch, bluematch + m, 0);
      if (match(i)) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int m, n;
int blue[505];
int red[505];

bool bluematch[505];
int redpair[30];

int path[505][505];

int gcd(int a, int b) {
  int m;

  while (1) {
    m = a % b;
    if (m == 0)
      return b;
    a = b;
    b = m;
  }
  return 1;
}

bool match(int x) {
  if (x < 0)
    return true;

  if (bluematch[x]) {
    return false;
  }
  bluematch[x] = true;

  for (int y = 0; y < n; y++) {
    if (!path[x][y])
      continue;
    if (match(redpair[y])) {
      redpair[y] = x;
      return true;
    }
  }

  return false;
}

int main() {
  ios_base::sync_with_stdio(0);

  int i, j, cnt;
  while (1) {
    cin >> m >> n;
    if (m == 0 || n == 0)
      return 0;

    for (i = 0; i < m; i++) {
      cin >> blue[i];
    }

    for (i = 0; i < n; i++) {
      cin >> red[i];
    }

    for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++) {
        if (gcd(blue[i], red[j]) != 1) {
          path[i][j] = 1;
        } else {
          path[i][j] = 0;
        }
      }
    }

    fill(redpair, redpair + n, -1);
    cnt = 0;
    for (i = 0; i < m; i++) {
      fill(bluematch, bluematch + m, 0);
      if (match(i)) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }

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

#include <stdio.h>

int main(void) {
  int x, y, N, n, d, i, j;
  int sx[200], sy[200];
  int SW, SS, SE, SN;
  while (1) {
    SW = SS = SE = SN = 0;
    scanf("%d", &N);
    if (N == 0)
      break;
    x = y = 0;
    sx[0] = x;
    sy[0] = y;
    for (i = 1; i < N; i++) {
      scanf("%d%d", &n, &d);
      x = sx[n];
      y = sy[n];
      if (d == 0)
        x--;
      else if (d == 1)
        y++;
      else if (d == 2)
        x++;
      else
        y--;
      sx[i] = x;
      sy[i] = y;
      if (SW > x)
        SW = x;
      else if (SS < y)
        SS = y;
      else if (SE < x)
        SE = x;
      else if (SN > y)
        SN = y;
    }
    printf("%d %d\\n", SE - SW + 1, SS - SN + 1);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int a[399][399];

void search(int *x, int *y, int n) {
  int i, j;
  for (i = 0; i < 400; i++) {
    for (j = 0; j < 400; j++) {
      if (a[i][j] == n) {
        *x = j;
        *y = i;
        break;
      }
    }
    if (a[i][j] == n)
      break;
  }
  return;
}

int main(void) {
  int x, y, N, n, d, i, j;
  int SW, SS, SE, SN;
  while (1) {
    for (i = 0; i < 400; i++)
      for (j = 0; j < 400; j++)
        a[i][j] = -1;
    SW = SS = SE = SN = 199;
    scanf("%d", &N);
    if (N == 0)
      break;
    x = 199;
    y = 199;
    a[x][y] = 0;
    for (i = 1; i < N; i++) {
      scanf("%d%d", &n, &d);
      search(&x, &y, n);
      if (d == 0)
        x--;
      else if (d == 1)
        y++;
      else if (d == 2)
        x++;
      else
        y--;
      a[y][x] = i;
      if (SW > x)
        SW = x;
      else if (SS < y)
        SS = y;
      else if (SE < x)
        SE = x;
      else if (SN > y)
        SN = y;
    }
    printf("%d %d\\n", SE - SW + 1, SS - SN + 1);
  }
  return 0;
}
Problem p00746 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

struct POINT {
  int x;
  int y;
};

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int main(void) {
  int N;
  while (cin >> N, N) {
    POINT minp = {0, 0};
    POINT maxp = {0, 0};

    vector<POINT> box(N);
    box[0].x = 0;
    box[0].y = 0;
    for (int i = 1; i < N; i++) {
      int n, d;
      cin >> n >> d;
      box[i].x = box[n].x + dx[d];
      box[i].y = box[n].y + dy[d];

      minp.x = min(minp.x, box[i].x);
      minp.y = min(minp.y, box[i].y);
      maxp.x = max(maxp.x, box[i].x);
      maxp.y = max(maxp.y, box[i].y);
    }

    // cerr << "--- ";
    cout << (maxp.x - minp.x + 1) << " " << (maxp.y - minp.y + 1) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

struct POINT {
  int x;
  int y;
};

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int main(void) {
  int N;
  while (cin >> N, N) {
    POINT minp = {0, 0};
    POINT maxp = {0, 0};

    vector<POINT> box(N);
    box[0].x = 0;
    box[0].y = 0;
    for (int i = 1; i < N; i++) {
      int n, d;
      cin >> n >> d;
      box[i].x = box[n].x + dx[d];
      box[i].y = box[n].y + dy[d];

      minp.x = min(minp.x, box[i].x);
      minp.y = min(minp.y, box[i].y);
      maxp.x = max(maxp.x, box[i].x);
      maxp.y = max(maxp.y, box[i].y);
    }

    cerr << "--- ";
    cout << (maxp.x - minp.x + 1) << " " << (maxp.y - minp.y + 1) << endl;
  }

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

#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;

int dy[4] = {0, -1, 0, 1};
int dx[4] = {-1, 0, 1, 0};

int main() {
  int n;
  int houkou, num;
  while (cin >> n, n) {
    vector<pii> ans(n);
    pii tmp;
    ans[0] = make_pair(0, 0);
    for (int i = 1; i < n; i++) {
      cin >> num >> houkou;
      tmp = ans[num];
      ans[i] = make_pair(tmp.first + dx[houkou], tmp.second + dy[houkou]);
    }
    int MaxX = 0, MaxY = 0, MinX = 0, MinY = 0;
    for (int i = 0; i < n; i++) {
      if (ans[i].first > MaxX)
        MaxX = ans[i].first;
      if (ans[i].first < MinX)
        MinX = ans[i].first;
      if (ans[i].second > MaxY)
        MaxY = ans[i].second;
      if (ans[i].second < MinY)
        MinY = ans[i].second;
      // cout << ans[i].first << " " << ans[i].second << endl;
    }
    cout << MaxX - MinX + 1 << " " << MaxY - MinY + 1 << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;

int M, T, P, R;

int main() {
  while (1) {
    cin >> M >> T >> P >> R;
    if (M == 0 && T == 0 && P == 0 && R == 0)
      break;

    vector<piii> pv(T);
    vector<vector<int>> end(T, vector<int>(P, 0));
    for (int i = 0; i < T; i++)
      pv[i] = make_pair(0, make_pair(0, i + 1));
    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      if (end[t - 1][p - 1] > 0)
        continue;
      if (m > M)
        continue;
      if (j == 0) {
        pv[t - 1].first++;
        pv[t - 1].second.first -= m;
        end[t - 1][p - 1] = (-1) * end[t - 1][p - 1];
      } else {
        end[t - 1][p - 1]--;
      }
    }

    for (int i = 0; i < T; i++) {
      for (int j = 0; j < P; j++) {
        if (end[i][j] <= 0)
          continue;
        pv[i].second.first -= 20 * end[i][j];
      }
    }

    sort(pv.begin(), pv.end());
    for (int i = T - 1; i >= 0; i--) {
      if (i > 0 && pv[i].first == pv[i - 1].first &&
          pv[i].second.first == pv[i - 1].second.first) {
        cout << pv[i].second.second << "=";
      } else {
        cout << pv[i].second.second;
        if (i > 0)
          cout << ",";
      }
    }
    cout << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for (LL i = 0; i < n; ++i)
#define FOR(i, a, n) for (LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[] = {0, -1, 0, 1};
int dx[] = {-1, 0, 1, 0};

// #define int long long

/*************** using variables ***************/
int N;
vector<int> n, d;
P coordinates[201];
/**********************************************/

void solve() {
  coordinates[0] = P(0, 0);
  REP(i, N - 1) {
    int cur = i + 1;
    int y = coordinates[n[i]].first + dy[d[i]];
    int x = coordinates[n[i]].second + dx[d[i]];
    coordinates[cur] = P(y, x);
  }

  int x_max_num = -INF;
  int y_max_num = -INF;
  int x_min_num = INF;
  int y_min_num = INF;
  REP(i, N) {
    x_max_num = max(x_max_num, coordinates[i].second);
    x_min_num = min(x_min_num, coordinates[i].second);
    y_max_num = max(y_max_num, coordinates[i].first);
    y_min_num = min(y_min_num, coordinates[i].first);
  }

  cout << x_max_num - x_min_num + 1 << " " << y_max_num - y_min_num + 1 << endl;
  return;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> N, N) {
    n.resize(N - 1);
    d.resize(N - 1);
    REP(i, N - 1) cin >> n[i] >> d[i];
    solve();
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for (LL i = 0; i < n; ++i)
#define FOR(i, a, n) for (LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[] = {0, -1, 0, 1};
int dx[] = {-1, 0, 1, 0};

// #define int long long

/*************** using variables ***************/
int N;
vector<int> n, d;
P coordinates[101];
/**********************************************/

void solve() {
  coordinates[0] = P(0, 0);
  REP(i, N - 1) {
    int cur = i + 1;
    int y = coordinates[n[i]].first + dy[d[i]];
    int x = coordinates[n[i]].second + dx[d[i]];
    coordinates[cur] = P(y, x);
  }

  int x_max_num = -INF;
  int y_max_num = -INF;
  int x_min_num = INF;
  int y_min_num = INF;
  REP(i, N) {
    x_max_num = max(x_max_num, coordinates[i].second);
    x_min_num = min(x_min_num, coordinates[i].second);
    y_max_num = max(y_max_num, coordinates[i].first);
    y_min_num = min(y_min_num, coordinates[i].first);
  }

  cout << x_max_num - x_min_num + 1 << " " << y_max_num - y_min_num + 1 << endl;
  return;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> N, N) {
    n.resize(N - 1);
    d.resize(N - 1);
    REP(i, N - 1) cin >> n[i] >> d[i];
    solve();
  }
}
Problem p00746 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#pragma warning(disable : 4996)
using namespace std;

const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    vector<int> xs;
    vector<int> ys;
    xs.emplace_back(0);
    ys.emplace_back(0);
    for (int i = 0; i < N - 1; ++i) {
      int n, d;
      cin >> n >> d;
      const int nx = xs[n] + dx[d];
      const int ny = ys[n] + dy[d];
      xs.emplace_back(nx);
      ys.emplace_back(ny);
    }
    const int width = *(max_element(xs.begin(), xs.end())) -
                      *(min_element(xs.begin(), xs.end()));
    const int height = *(max_element(ys.begin(), ys.end())) -
                       *(min_element(ys.begin(), ys.end()));
    cout << width + 1 << " " << height + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#pragma warning(disable : 4996)
using namespace std;

const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  while (1) {
    int N;
    cin >> N;
    vector<int> xs;
    vector<int> ys;
    xs.emplace_back(0);
    ys.emplace_back(0);
    for (int i = 0; i < N - 1; ++i) {
      int n, d;
      cin >> n >> d;
      const int nx = xs[n] + dx[d];
      const int ny = ys[n] + dy[d];
      xs.emplace_back(nx);
      ys.emplace_back(ny);
    }
    const int width = *(max_element(xs.begin(), xs.end())) -
                      *(min_element(xs.begin(), xs.end()));
    const int height = *(max_element(ys.begin(), ys.end())) -
                       *(min_element(ys.begin(), ys.end()));
    cout << width + 1 << " " << height + 1 << endl;
  }
  return 0;
}
Problem p00746 (C++) — buggy submission, verdict: Runtime Error

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

bool SortXPos(pair<int, int> pos1, pair<int, int> pos2) {
  return pos1.first < pos2.first ? true : false;
}
bool SortYPos(pair<int, int> pos1, pair<int, int> pos2) {
  return pos1.second < pos2.second ? true : false;
}

int main(void) {
  int num;
  while (cin >> num) {
    if (num == 0)
      break;
    vector<pair<int, int>> pos(num);
    pos[0].first = 0;
    pos[0].second = 0;

    for (int i = 1; i < num; i++) {
      int base, action;
      cin >> base >> action;

      switch (action) {
      case 0:
        pos[i].first = pos[base].first - 1;
        pos[i].second = pos[base].second;
        break;
      case 1:
        pos[i].first = pos[base].first;
        pos[i].second = pos[base].second - 1;
        break;
      case 2:
        pos[i].first = pos[base].first + 1;
        pos[i].second = pos[base].second;
        break;
      case 3:
        pos[i].first = pos[base].first;
        pos[i].second = pos[base].second + 1;
        break;
      }
    }

    sort(pos.begin(), pos.end(), SortXPos);
    int xlength = pos[num - 1].first - pos[0].first + 1;
    sort(pos.begin(), pos.end(), SortYPos);
    int ylength = pos[num - 1].second - pos[0].second + 1;

    cout << xlength << ' ' << ylength << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

bool SortXPos(pair<int, int> pos1, pair<int, int> pos2) {
  return pos1.first < pos2.first ? true : false;
}
bool SortYPos(pair<int, int> pos1, pair<int, int> pos2) {
  return pos1.second < pos2.second ? true : false;
}

int main(void) {
  int num;
  while (cin >> num) {
    vector<pair<int, int>> pos(num);
    pos[0].first = 0;
    pos[0].second = 0;

    for (int i = 1; i < num; i++) {
      int base, action;
      cin >> base >> action;

      switch (action) {
      case 0:
        pos[i].first = pos[base].first - 1;
        pos[i].second = pos[base].second;
        break;
      case 1:
        pos[i].first = pos[base].first;
        pos[i].second = pos[base].second - 1;
        break;
      case 2:
        pos[i].first = pos[base].first + 1;
        pos[i].second = pos[base].second;
        break;
      case 3:
        pos[i].first = pos[base].first;
        pos[i].second = pos[base].second + 1;
        break;
      }
    }

    sort(pos.begin(), pos.end(), SortXPos);
    int xlength = pos[num - 1].first - pos[0].first + 1;
    sort(pos.begin(), pos.end(), SortYPos);
    int ylength = pos[num - 1].second - pos[0].second + 1;

    cout << xlength << ' ' << ylength << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int dp[2][1000000];
int v[250];
int main() {
  int n;
  for (int j = 0; j < 1000000; j++) {
    dp[0][j] = 999999;
    dp[1][j] = 999999;
  }
  dp[0][0] = 0;
  dp[1][0] = 0;
  for (int i = 1; i < 250; i++) {
    int k = i * (i + 1) * (i + 2) / 6;
    if (k >= 1000000)
      break;
    v[i - 1] = k;
  }
  for (int i = 0; i < 1000000; i++) {
    for (int j = 0; j < 250; j++) {
      if (i + v[j] >= 1000000)
        break;
      dp[0][i + v[j]] = min(dp[0][i + v[j]], dp[0][i] + 1);
      if (v[j] % 2 == 0)
        continue;
      dp[1][i + v[j]] = min(dp[1][i + v[j]], dp[1][i] + 1);
    }
  }
  while (cin >> n && n != 0) {
    cout << dp[0][n] << " " << dp[1][n] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int dp[2][1000001];
int v[1000];
int main() {
  int n;
  for (int j = 0; j <= 1000000; j++) {
    dp[0][j] = 999999;
    dp[1][j] = 999999;
  }
  dp[0][0] = 0;
  dp[1][0] = 0;
  for (int i = 1;; i++) {
    int k = i * (i + 1) * (i + 2) / 6;
    if (k > 1000000)
      break;
    v[i - 1] = k;
  }
  for (int i = 0; i <= 1000000; i++) {
    for (int j = 0;; j++) {
      if (i + v[j] > 1000000)
        break;
      dp[0][i + v[j]] = min(dp[0][i + v[j]], dp[0][i] + 1);
      if (v[j] % 2 == 0)
        continue;
      dp[1][i + v[j]] = min(dp[1][i + v[j]], dp[1][i] + 1);
    }
  }
  while (cin >> n && n != 0) {
    cout << dp[0][n] << " " << dp[1][n] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

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

int dp[1000000];
int dpodd[1000000];
int num[200];
int INF = 10000000;
int main() {
  for (int i = 0; i < 200; i++) {
    num[i] = (i + 1) * (i + 2) * (i + 3) / 6;
  }
  dp[0] = 0;
  dpodd[0] = 0;
  for (int i = 1; i < 1000000; i++) {
    dp[i] = INF;
    dpodd[i] = INF;
    for (int j = 0; num[j] <= i; j++) {
      dp[i] = min(dp[i], dp[i - num[j]] + 1);
      if (num[j] % 2 == 1) {
        dpodd[i] = min(dpodd[i], dpodd[i - num[j]] + 1);
      }
    }
  }
  int N;
  while (cin >> N, N) {
    cout << dp[N] << " " << dpodd[N] << endl;
  }
}

Error: 0

Fixed submission:

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

int dp[100000];
int dpodd[100000];
int num[200];
int INF = 1000000;
int main() {
  for (int i = 0; i < 200; i++) {
    num[i] = (i + 1) * (i + 2) * (i + 3) / 6;
  }
  dp[0] = 0;
  dpodd[0] = 0;
  for (int i = 1; i < 100000; i++) {
    dp[i] = INF;
    dpodd[i] = INF;
    for (int j = 0; num[j] <= i; j++) {
      dp[i] = min(dp[i], dp[i - num[j]] + 1);
      if (num[j] % 2 == 1) {
        dpodd[i] = min(dpodd[i], dpodd[i - num[j]] + 1);
      }
    }
  }
  int N;
  while (cin >> N, N) {
    cout << dp[N] << " " << dpodd[N] << endl;
  }
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;
#define MAX 1000000
#define INF 1000000000

int dp1[MAX + 1], dp2[MAX + 1];

int main() {
  for (int i = 1; i <= MAX; i++) {
    dp1[i] = INF;
    dp2[i] = INF;
  }

  for (int n = 1; n * (n + 1) * (n + 2) / 6 <= MAX; n++) {
    int a = n * (n + 1) * (n + 2) / 6;
    for (int i = a; i < MAX; i++) {
      dp1[i] = min(dp1[i], dp1[i - a] + 1);
    }
    if (a % 2 == 0)
      continue;
    for (int i = a; i < MAX; i++) {
      dp2[i] = min(dp2[i], dp2[i - a] + 1);
    }
  }

  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    cout << dp1[n] << " " << dp2[n] << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

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

int n;
int memo1[1000001], memo2[1000001], memoodd[1000001], memo3[1000001];

int pollock_1(int n) {
  int min = 100, ex;
  if (n == memo1[n])
    return memo2[n] = 1;
  if (memo2[n] > 0)
    return memo2[n];
  for (int i = 1; i < 1000001; i++) {
    if (i <= n / 2) {
      if (pollock_1(n - i) == 1) {
        ex = pollock_1(n - i) + pollock_1(i);
      }
      if (i == 1) {
        ex = pollock_1(n - 1) + 1;
      }
      if (ex < min)
        min = ex;
    }
  }
  return memo2[n] = min;
}

int pollock_2(int n) {
  int min = 10000000, ex;
  if (n == memoodd[n])
    return memo2[n] = 1;
  if (memo3[n] > 0)
    return memo3[n];
  for (int i = 1; i < 1000001; i++) {
    if (i <= n / 2) {
      if (pollock_2(n - i) == 1) {
        ex = pollock_2(n - i) + pollock_2(i);
      }
      if (i == 1) {
        ex = pollock_2(n - 1) + 1;
      }
      if (ex < min)
        min = ex;
    }
  }
  return memo3[n] = min;
}

int main() {
  for (int k = 0; k < 1000001; k++) {
    memo1[k] = 0;
    memo2[k] = 0;
    memoodd[k] = 0;
    memo3[k] = 0;
  }
  for (int k = 1; k < 200; k++) {
    n = (k * (k + 1) * (k + 2)) / 6;
    memo1[n] = n;
    if (n % 2 != 0)
      memoodd[n] = n;
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    printf("%d %d\\n", pollock_1(n), pollock_2(n));
  }
}