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

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

// #define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, x, ...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__, REP1, REP2, REP3))(__VA_ARGS__)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond)                                                          \\
  if (cond)                                                                    \\
    break;                                                                     \\
  else

template <typename T> inline void input(vector<T> &v) {
  for (auto &x : v)
    cin >> x;
}

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

const int INF = 1 << 29;

signed main() {
  int n;
  while (cin >> n && n) {
    int t, l, b;
    cin >> t >> l >> b;
    vector<int> stage(n + 1);
    rep(i, l) {
      int lose;
      cin >> lose;
      stage[lose] = 1;
    }
    rep(i, b) {
      int back;
      cin >> back;
      stage[back] = 2;
    }
    vector<vector<double>> dp(t + 1, vector<double>(n + 1));
    dp[0][0] = 1;
    rep(i, t) rep(j, n) rep(d, 6) {
      int next = j + d + 1;
      if (next > n)
        next = n - (next % n);
      double val = dp[i][j] * (1. / 6.);
      if (stage[next] == 1 && i + 2 <= t) {
        dp[i + 2][next] += val;
      } else if (stage[next] == 2) {
        dp[i + 1][0] += val;
      } else {
        dp[i + 1][next] += val;
      }
    }
    double ans = 0;
    rep(i, t + 1) ans += dp[i][n];
    printf("%.8f\\n", ans);
  }
}

Error: WA

Fixed submission:

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

// #define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, x, ...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__, REP1, REP2, REP3))(__VA_ARGS__)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond)                                                          \\
  if (cond)                                                                    \\
    break;                                                                     \\
  else

template <typename T> inline void input(vector<T> &v) {
  for (auto &x : v)
    cin >> x;
}

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

const int INF = 1 << 29;

signed main() {
  int n;
  while (cin >> n) {
    int t, l, b;
    cin >> t >> l >> b;
    vector<int> stage(n + 1);
    rep(i, l) {
      int lose;
      cin >> lose;
      stage[lose] = 1;
    }
    rep(i, l) {
      int back;
      cin >> back;
      stage[back] = 2;
    }
    vector<vector<double>> dp(t + 1, vector<double>(n + 1));
    dp[0][0] = 1;
    rep(i, t) rep(j, n) rep(d, 6) {
      int next = j + d + 1;
      if (next > n)
        next = n - (next % n);
      double val = dp[i][j] * (1. / 6.);
      if (stage[next] == 1 && i + 2 <= t) {
        dp[i + 2][next] += val;
      } else if (stage[next] == 2) {
        dp[i + 1][0] += val;
      } else {
        dp[i + 1][next] += val;
      }
    }
    double ans = 0;
    rep(i, t + 1) ans += dp[i][n];
    printf("%.8f\\n", ans);
  }
}