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

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
using P = pair<int, int>;

int X, Y,
    Z; //????????¬??????????¨?????????°???????????°??????????????????????????°
int roulette[4];
P eventInfo[60] = {P(0, 0)};
double dp[60][6000] = {};

void inputRoulette() {
  for (int i = 0; i < X; i++) {
    cin >> roulette[i];
  }
}
void inputEventInfo() {
  for (int i = 0; i < Z; i++) {
    int n, e, a;
    cin >> n >> e >> a;
    eventInfo[n].first = e;
    eventInfo[n].second = a;
  }
}

void solve() {
  dp[0][0] = 1.0;
  for (int i = 0; i < Y; i++) {
    for (int j = 0; j < Y * 100; j++) {
      if (dp[i][j] == 0)
        continue;
      for (int k = 0; k < X; k++) {
        int nextPos = min(Y, i + roulette[k]);
        int nextMoney = j;
        int eventType = eventInfo[nextPos].first;
        int eventValue = eventInfo[nextPos].second;

        if (eventType == 1)
          nextPos = min(Y, i + roulette[k] + eventValue);
        if (eventType == 2)
          nextMoney = j + eventValue;
        if (eventType == 3)
          nextMoney = max(0, j - eventValue);
        dp[nextPos][nextMoney] += dp[i][j] / X;
      }
    }
  }
}
double getAnswer() {
  double ans = 0;
  for (int i = 0; i < Y * 100; i++) {
    ans += i * dp[Y][i];
  }
  return ans;
}
void clear() {
  for (int i = 0; i < 60; i++) {
    for (int j = 0; j < 6000; j++) {
      dp[i][j] = 0;
    }
  }

  for (int i = 0; i < 60; i++) {
    eventInfo[i] = P(0, 0);
  }
}

int main() {
  while (cin >> X >> Y >> Z, X + Y + Z) {
    clear();
    inputRoulette();
    inputEventInfo();
    solve();
    cout << (int)getAnswer() << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
using P = pair<int, int>;

int X, Y,
    Z; //????????¬??????????¨?????????°???????????°??????????????????????????°
int roulette[4];
P mapInfo[60] = {P(0, 0)};
double dp[60][6000] = {};

void inputRoulette() {
  for (int i = 0; i < X; i++) {
    cin >> roulette[i];
  }
}
void inputMapInfo() {
  for (int i = 0; i < Z; i++) {
    int n, e, a;
    cin >> n >> e >> a;
    mapInfo[n].first = e;
    mapInfo[n].second = a;
  }
}
int clamp_(int v, int min_, int max_) {
  if (v < min_)
    return min_;
  if (v > max_)
    return max_;
  return v;
}

void solve() {
  dp[0][0] = 1.0;
  for (int i = 0; i < Y; i++) {
    for (int j = 0; j < 6000; j++) {
      if (dp[i][j] == 0)
        continue;
      for (int k = 0; k < X; k++) {
        int nextPos = clamp_(i + roulette[k], 0, Y);
        int eventType = mapInfo[nextPos].first;
        int eventValue = mapInfo[nextPos].second;
        if (eventType == 0) {
          dp[nextPos][j] += dp[i][j] / X;
        }
        if (eventType == 1) {
          nextPos += clamp_(nextPos + eventValue, 0, Y);
          dp[nextPos][j] += dp[i][j] / X;
        }
        if (eventType == 2) {
          int point = j + eventValue;
          dp[nextPos][point] += dp[i][j] / X;
        }
        if (eventType == 3) {
          int point = clamp_(j - eventValue, 0, 6000);
          dp[nextPos][point] += dp[i][j] / X;
        }
      }
    }
  }
}
double getAnswer() {
  double ans = 0;
  for (int i = 0; i < 6000; i++) {
    ans += i * dp[Y][i];
  }
  return ans;
}
void clear() {
  for (int i = 0; i < 60; i++) {
    for (int j = 0; j < 6000; j++) {
      dp[i][j] = 0;
    }
  }
}

int main() {
  while (cin >> X >> Y >> Z, X + Y + Z) {
    clear();
    inputRoulette();
    inputMapInfo();
    solve();
    cout << (int)getAnswer() << endl;
  }

  return 0;
}