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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cout << *i << " ";
  cout << endl;
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main() {
  int N, T, L, B;
  while (cin >> N >> T >> L >> B && N) {
    bool lose[105] = {};
    bool back[105] = {};
    REP(i, L) {
      int k;
      cin >> k;
      assert(k < 100);
      lose[k] = true;
    }
    REP(i, B) {
      int k;
      cin >> k;
      assert(k < 100);
      back[k] = true;
    }
    double dp[102][101] = {};
    dp[0][0] = 1;
    REP(t, T) {
      REP(x, N) if (dp[t][x] > 0) {
        for (int d = 1; d <= 6; d++) {
          int next = x + d;
          if (next > N)
            next = N - (next - N);
          if (lose[next]) {
            dp[t + 2][next] += dp[t][x] * 1.0 / 6.0;
          } else if (back[next]) {
            dp[t + 1][0] += dp[t][x] * 1.0 / 6.0;
          } else {
            dp[t + 1][next] += dp[t][x] * 1.0 / 6.0;
          }
        }
      }
      // dp[t + 1][N] += dp[t][N];
    }
    double ans = 0;
    REP(t, T) ans += dp[t + 1][N];
    printf("%.10lf\\n", ans);
    // cout<<dp[T][N]<<endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cout << *i << " ";
  cout << endl;
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main() {
  int N, T, L, B;
  while (cin >> N >> T >> L >> B && N) {
    bool lose[105] = {};
    bool back[105] = {};
    REP(i, L) {
      int k;
      cin >> k;
      assert(k < 100);
      lose[k] = true;
    }
    REP(i, B) {
      int k;
      cin >> k;
      assert(k < 100);
      back[k] = true;
    }
    double dp[102][101] = {};
    dp[0][0] = 1;
    REP(t, T + 1) {
      REP(x, N) if (dp[t][x] > 0) {
        for (int d = 1; d <= 6; d++) {
          int next = x + d;
          if (next > N)
            next = N - (next - N);
          if (lose[next]) {
            dp[t + 2][next] += dp[t][x] * 1.0 / 6.0;
          } else if (back[next]) {
            dp[t + 1][0] += dp[t][x] * 1.0 / 6.0;
          } else {
            dp[t + 1][next] += dp[t][x] * 1.0 / 6.0;
          }
        }
      }
      // dp[t + 1][N] += dp[t][N];
    }
    double ans = 0;
    REP(t, T) ans += dp[t + 1][N];
    printf("%.10lf\\n", ans);
    // cout<<dp[T][N]<<endl;
  }
  return 0;
}