Problem p00232 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int main() {
  // freopen("test.txt", "r", stdin);
  int x, y, z;
  while (cin >> x >> y >> z, x | y | z) {
    vector<int> dice(x);
    rep(i, x) cin >> dice[i];
    vector<P> ev(y + 1, MP(0, 0));
    rep(i, z) {
      int n, e, a;
      cin >> n >> e >> a;
      ev[n] = MP(e, a);
    }

    vector<vector<double>> dp(y + 1, vector<double>(z * 100 + 1, 0.0));
    dp[0][0] = 1.0;

    for (int i = 0; i < y; i++) {
      rep(j, x) {
        int next = i + dice[j];
        int money = 0;
        if (next > y)
          next = y;
        switch (ev[next].first) {
        case 1:
          next += ev[next].second;
          break;
        case 2:
          money += ev[next].second;
          break;
        case 3:
          money -= ev[next].second;
          break;
        default:
          break;
        }
        if (next > y)
          next = y;
        for (int k = 0; k <= min(z * 100, z * 100 - money); k++) {
          int m = k + money;
          if (m < 0)
            m = 0;
          dp[next][m] += dp[i][k] / x;
        }
      }
    }

    // cout << "***";
    double sum = 0;
    rep(i, z * 100 + 1) sum += i * dp[y][i];
    cout << (int)sum << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int main() {
  int x, y, z;
  while (cin >> x >> y >> z, x | y | z) {
    vector<int> dice(x);
    rep(i, x) cin >> dice[i];
    vector<P> ev(y + 1, MP(0, 0));
    rep(i, z) {
      int n, e, a;
      cin >> n >> e >> a;
      ev[n] = MP(e, a);
    }

    vector<vector<double>> dp(y + 1, vector<double>(5000 + 1, 0));
    dp[0][0] = 1.0;

    for (int i = 0; i < y; i++) {
      rep(j, x) {
        int next = i + dice[j];
        if (next > y)
          next = y;
        int money = 0;
        switch (ev[next].first) {
        case 1:
          next += ev[next].second;
          break;
        case 2:
          money += ev[next].second;
          break;
        case 3:
          money -= ev[next].second;
          break;
        default:
          break;
        }
        for (int k = 0; k <= min(y * 100, y * 100 - money); k++) {
          int m = k + money;
          if (m < 0)
            m = 0;
          dp[next][m] += dp[i][k] / x;
        }
      }
    }

    // cout << "***";
    int sum = 0;
    rep(i, y * 100 + 1) sum += i * dp[y][i];
    cout << sum << endl;
  }

  return 0;
}