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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define mp(a, b) make_pair((a), (b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;

// →↑←↓
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};

const double EPS = 1e-9;

const char lose = 'l';
const char back = 'b';
const char goal = 'g';
int main() {
  cout << fixed << setprecision(10);
  while (true) {
    int N, T, L, B;
    cin >> N >> T >> L >> B;
    if (N == 0)
      break;
    vector<char> S(N + 1);

    for (int i = 0; i < L; i++) {
      int l;
      cin >> l;
      S[l] = lose;
    }
    for (int i = 0; i < B; i++) {
      int l;
      cin >> l;
      S[l] = back;
    }
    S[N] = goal;

    vector<vector<double>> dp(T + 3, vector<double>(N + 1));
    double goaled = 0;
    dp[0][0] = 1;
    for (int i = 0; i < T; i++) {
      for (int j = 0; j < N; j++) {
        for (int k = 1; k <= 6; k++) {
          double nyan = dp[i][j] / 6;
          int p = j + k;
          if (p > N) {
            p -= 2 * (p - N);
          }
          if (S[p] == lose) {
            dp[i + 2][p] += nyan;
          } else if (S[p] == back) {
            dp[i + 1][0] += nyan;
          } else if (S[p] == goal) {
            goaled += nyan;
          } else {
            dp[i + 1][p] += nyan;
          }
        }
      }
    }
    cout << goaled << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define mp(a, b) make_pair((a), (b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;

// →↑←↓
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};

const double EPS = 1e-9;

const char lose = 'l';
const char back = 'b';
const char goal = 'g';
int main() {
  cout << fixed << setprecision(10);
  int N, T, L, B;
  cin >> N >> T >> L >> B;
  vector<char> S(N + 1);

  for (int i = 0; i < L; i++) {
    int l;
    cin >> l;
    S[l] = lose;
  }
  for (int i = 0; i < B; i++) {
    int l;
    cin >> l;
    S[l] = back;
  }
  S[N] = goal;

  vector<vector<double>> dp(T + 3, vector<double>(N + 1));
  double goaled = 0;
  dp[0][0] = 1;
  for (int i = 0; i < T; i++) {
    for (int aa = 0; aa < N + 1; aa++) {
      cerr << dp[i][aa] << " ";
    }
    cerr << endl;
    for (int j = 0; j < N; j++) {
      for (int k = 1; k <= 6; k++) {
        double nyan = dp[i][j] / 6;
        int p = j + k;
        if (p > N) {
          p -= 2 * (p - N);
        }
        if (S[p] == lose) {
          dp[i + 2][p] += nyan;
        } else if (S[p] == back) {
          dp[i + 1][0] += nyan;
        } else if (S[p] == goal) {
          goaled += nyan;
        } else {
          dp[i + 1][p] += nyan;
        }
      }
    }
  }
  cout << goaled << endl;
  return 0;
}