alexjercan/bugnet huggingface dataset:
Problem p00855 (C++) — buggy submission, verdict: Runtime Error


#include <iostream>
#include <vector>
using namespace std;

int pmem[1300000];
vector<int> prime;
void init() {
  for (int i = 2; i < 1300000; i++) {
    if (pmem[i])
      continue;
    pmem[i] = 1;
    prime.push_back(i);
    for (int j = i + i; j < 1300000; j += i)
      pmem[j] = -1;
  }
}

int main() {
loop:
  init();
  int n;
  cin >> n;
  if (!n)
    return 0;
  for (int i = 0; i < prime.size(); i++) {
    if (prime[i] == n) {
      cout << 0 << endl;
      goto loop;
    }
    if (prime[i] > n) {
      cout << prime[i] - prime[i - 1] << endl;
      goto loop;
    }
  }
}

Error: -11

Fixed submission:


#include <iostream>
#include <vector>
using namespace std;

int pmem[130000];
vector<int> prime;
void init() {
  for (int i = 2; i < 1300000; i++) {
    if (pmem[i])
      continue;
    pmem[i] = 1;
    prime.push_back(i);
    for (int j = i + i; j < 1300000; j += i)
      pmem[j] = -1;
  }
}

int main() {
loop:
  init();
  int n;
  cin >> n;
  if (!n)
    return 0;
  for (int i = 0; i < prime.size(); i++) {
    if (prime[i] == n) {
      cout << 0 << endl;
      goto loop;
    }
    if (prime[i] > n) {
      cout << prime[i] - prime[i - 1] << endl;
      goto loop;
    }
  }
}
Problem p00855 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define INF 999999999

bool pr[1300000];

void erato() {
  pr[0] = 0;
  pr[1] = 0;
  pr[2] = 1;
  for (int i = 3; i < 1300000; i++) {
    pr[i] = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        pr[i] = 0;
        break;
      }
    }
  }
}

int main() {
  int i, j, n;
  int ans;
  erato();
  while (1) {
    cin >> n;
    if (!n)
      break;
    if (pr[n])
      cout << "0" << endl;
    else {
      int less = n - 1;
      while (!pr[less]) {
        less--;
      }
      int more = n + 1;
      while (!pr[more]) {
        more++;
      }
      cout << more - less << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define INF 999999999

bool pr[1000000];

void erato() {
  pr[0] = 0;
  pr[1] = 0;
  pr[2] = 1;
  for (int i = 3; i < 1000000; i++) {
    pr[i] = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        pr[i] = 0;
        break;
      }
    }
  }
}

int main() {
  int i, j, n;
  int ans;
  erato();
  while (1) {
    cin >> n;
    if (!n)
      break;
    if (pr[n])
      cout << "0" << endl;
    else {
      int less = n - 1;
      while (!pr[less]) {
        less--;
      }
      int more = n + 1;
      while (!pr[more]) {
        more++;
      }
      cout << more - less << endl;
    }
  }
  return 0;
}
Problem p00856 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int cell[101], n;
double mem[101][101];

double solve(int k, int t) {
  if (mem[k][t] > -0.5)
    return mem[k][t];
  if (k == n)
    return 1;
  if (t <= 0)
    return 0;
  double res = 0;
  rep(i, 6) {
    int next = k + i + 1;
    if (next > n)
      next = 2 * n - next;
    if (cell[next] == 2)
      next = 0;
    res += solve(next, t - 1 - (cell[next] == 1 ? 1 : 0));
  }
  return mem[k][t] = res /= 6;
}

int main() {
  int t, l, b, c;
  while (cin >> n >> t >> l >> b, n) {
    rep(i, n + 1) rep(j, t + 1) mem[i][j] = -1;
    rep(i, n + 1) cell[i] = 0;
    rep(i, l) {
      cin >> c;
      cell[c] = 1;
    }
    rep(i, b) {
      cin >> c;
      cell[c] = 2;
    }
    printf("%.12lf\\n", solve(0, t));
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int cell[101], n;
double mem[101][101];

double solve(int k, int t) {
  if (mem[k][t] >= 0)
    return mem[k][t];
  double res = 0;
  rep(i, 6) {
    int next = k + i + 1;
    if (next > n)
      next = 2 * n - next;
    if (cell[next] == 2)
      next = 0;
    res += solve(next, t - 1 - (cell[next] == 1 ? 1 : 0));
  }
  return mem[k][t] = res /= 6;
}

int main() {
  int t, l, b;
  while (cin >> n >> t >> l >> b, n) {
    rep(i, n + 1) rep(j, t + 1) mem[i][j] = -1;
    rep(i, n + 1) mem[i][0] = 0;
    rep(i, t + 1) mem[n][i] = 1;
    rep(i, n + 1) cell[i] = 0;
    rep(i, l) {
      int c;
      cin >> c;
      cell[c] = 1;
    }
    rep(i, b) {
      int c;
      cin >> c;
      cell[c] = 2;
    }
    cout.precision(12);
    cout << solve(0, t) << endl;
  }
  return 0;
}
Problem p00856 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int N, T, L, B;

int next(int cur, int dice) {
  int ret = cur + dice;
  if (N < ret)
    ret = N - (ret - N);
  return ret;
}

int main() {
  ios::sync_with_stdio(false);

  while (cin >> N >> T >> L >> B && (N || T || L || B)) {
    string LB = "                                                              "
                "                                       ";
    int k;
    for (int i = 0; i < L; ++i) {
      cin >> k;
      LB[k] = 'L';
    }
    for (int i = 0; i < B; ++i) {
      cin >> k;
      LB[k] = 'B';
    }

    double p[101][101][2] = {0};
    p[0][0][0] = 1.0;
    for (int i = 0; i < T; ++i) {
      for (int j = 0; j < N; ++j) {
        for (int k = 1; k <= 6; ++k) {
          int ne = next(j, k);
          if (LB[ne] == 'B')
            ne = 0;
          p[i + 1][ne][LB[ne] == 'L'] += p[i][j][0] / 6.0;
        }
        p[i + 1][j][0] += p[i][j][1];
      }
    }

    double ans = 0;
    for (int i = 0; i <= T; ++i)
      ans += p[i][N][1] + p[i][N][0];
    cout << setprecision(6) << fixed << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int N, T, L, B;

int next(int cur, int dice) {
  int ret = cur + dice;
  if (N < ret)
    ret = N - (ret - N);
  return ret;
}

int main() {
  ios::sync_with_stdio(false);

  while (cin >> N >> T >> L >> B && (N || T || L || B)) {
    string LB(' ', 101);
    int k;
    for (int i = 0; i < L; ++i) {
      cin >> k;
      LB[k] = 'L';
    }
    for (int i = 0; i < B; ++i) {
      cin >> k;
      LB[k] = 'B';
    }

    double p[101][101][2] = {0};
    p[0][0][0] = 1.0;
    for (int i = 0; i < T; ++i) {
      for (int j = 0; j < N; ++j) {
        for (int k = 1; k <= 6; ++k) {
          int ne = next(j, k);
          if (LB[ne] == 'B')
            ne = 0;
          p[i + 1][ne][LB[ne] == 'L'] += p[i][j][0] / 6.0;
        }
        p[i + 1][j][0] += p[i][j][1];
      }
    }

    double ans = 0;
    for (int i = 0; i <= T; ++i)
      ans += p[i][N][1] + p[i][N][0];
    cout << setprecision(6) << fixed << ans << endl;
  }
  return 0;
}
Problem p00856 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define MAX 501
typedef pair<int, int> pii;

int N, T, L, B;
int arr[MAX];

double solve() {
  double dp[MAX][MAX]; // dp[ターン数][どのマスにいるか]
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 1; i <= T; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < 6; k++) {
        if (dp[i - 1][j] == 0)
          continue;
        int next = j + (k + 1);
        if (next > N) {
          next = next - 2 * (next - N);
        }
        switch (arr[next]) {
        case 0:
          dp[i][next] += dp[i - 1][j] / 6;
          break;
        case 1:
          dp[i + 1][next] += dp[i - 1][j] / 6;
          break;
        case 2:
          dp[i][0] += dp[i - 1][j] / 6;
          break;
        }
      }
    }
  }
  double res = 0;
  for (int i = 1; i <= T; i++) {
    res += dp[i][N];
  }
  return res;
}

int main() {
  int in;
  while (cin >> N >> T >> L >> B, N) {
    memset(arr, 0, sizeof(arr));
    for (int i = 0; i < L; i++) {
      cin >> in;
      arr[in] = 1;
    }
    for (int i = 0; i < B; i++) {
      cin >> in;
      arr[in] = 2;
    }
    printf("%.8f\\n", solve());
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define MAX 101
typedef pair<int, int> pii;

int N, T, L, B;
int arr[MAX];

double solve() {
  double dp[MAX][MAX]; // dp[ターン数][どのマスにいるか]
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 1; i <= T; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < 6; k++) {
        if (dp[i - 1][j] == 0)
          continue;
        int next = j + (k + 1);
        if (next > N) {
          next = next - 2 * (next - N);
        }
        switch (arr[next]) {
        case 0:
          dp[i][next] += dp[i - 1][j] / 6;
          break;
        case 1:
          dp[i + 1][next] += dp[i - 1][j] / 6;
          break;
        case 2:
          dp[i][0] += dp[i - 1][j] / 6;
          break;
        }
      }
    }
  }
  double res = 0;
  for (int i = 1; i <= T; i++) {
    res += dp[i][N];
  }
  return res;
}

int main() {
  int in;
  while (cin >> N >> T >> L >> B, N) {
    memset(arr, 0, sizeof(arr));
    for (int i = 0; i < L; i++) {
      cin >> in;
      arr[in] = 1;
    }
    for (int i = 0; i < B; i++) {
      cin >> in;
      arr[in] = 2;
    }
    printf("%.8f\\n", solve());
  }
  return 0;
}
Problem p00856 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct Edge {
  int from, to;
  ll cost;
};

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main() {
  int n, t, l, b;
  while (scanf("%d%d%d%d", &n, &t, &l, &b) && n) {
    char board[101];
    fill(board, board + 101, ' ');
    int tmp;
    rep(l) {
      scanf("%d", &tmp);
      board[tmp] = 'l';
    }
    rep(b) {
      scanf("%d", &tmp);
      board[tmp] = 'b';
    }

    long double dp[t + 2][n + 1];
    fill(dp[0], dp[t + 2], 0.0);
    dp[0][0] = 1.0;
    repp(tt, t) {
      rep(n) {
        long double inc = dp[tt][i] * 1.0 / 6.0;
        reppp(dice, 1, 7) {
          int next = min(i + dice, 2 * n - (i + dice));
          if (board[next] == 'l') {
            if (next == n || tt + 1 == t) {
              dp[tt + 1][next] += inc;
            } else {
              dp[tt + 2][next] += inc;
            }
          } else if (board[next] == 'b') {
            dp[tt + 1][0] += inc;
          } else {
            dp[tt + 1][next] += inc;
          }
        }
      }
    }

    long double ans = 0.0;
    repp(tt, t + 1) { ans += dp[tt][n]; }
    printf("%.6Lf\\n", ans);
  }
}


Error: -7

Fixed submission:

#include <bits/stdc++.h>

#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct Edge {
  int from, to;
  ll cost;
};

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main() {
  int n, t, l, b;
  while (scanf("%d%d%d%d", &n, &t, &l, &b) && n) {
    char board[101];
    int tmp;
    rep(l) {
      scanf("%d", &tmp);
      board[tmp] = 'l';
    }
    rep(b) {
      scanf("%d", &tmp);
      board[tmp] = 'b';
    }

    double dp[t + 1][n + 1];
    fill(dp[0], dp[t + 1], 0.0);
    dp[0][0] = 1.0;
    repp(tt, t) {
      rep(n) {
        reppp(dice, 1, 7) {
          int next = min(i + dice, 2 * n - (i + dice));
          if (board[next] == 'l') {
            dp[tt + 2][next] += dp[tt][i] * 1.0 / 6.0;
          } else if (board[next] == 'b') {
            dp[tt + 1][0] += dp[tt][i] * 1.0 / 6.0;
          } else {
            dp[tt + 1][next] += dp[tt][i] * 1.0 / 6.0;
          }
        }
      }
    }

    double ans = 0.0;
    repp(tt, t + 1) { ans += dp[tt][n]; }
    printf("%.6lf\\n", ans);
  }
}
Problem p00856 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

const double kProbability = 1.0f / 6.0f;
const int kMaxSquare = 128;
const int kMaxTurn = 128;

enum BoardState { BLANK, LOSE, BACK };

BoardState board[kMaxSquare];

double bp(const int N, const int T) {
  double prob[kMaxTurn][kMaxSquare];
  for (int i = 0; i <= T; i++)
    for (int j = 0; j <= N; j++)
      prob[i][j] = 0.0f;
  prob[0][0] = 1.0f;

  for (int t = 0; t < T; t++) {
    for (int n = 0; n < N; n++) {
      if (prob[t][n] == 0.0f)
        continue;
      for (int dice = 1; dice <= 6; dice++) {
        int pos = (n + dice <= N) ? n + dice : N - (n + dice - N);
        switch (board[pos]) {
        case BLANK:
          prob[t + 1][pos] += prob[t][n] * kProbability;
          break;
        case LOSE:
          prob[t + 2][pos] += prob[t][n] * kProbability;
          break;
        case BACK:
          prob[t + 1][0] += prob[t][n] * kProbability;
        }
      }
    }
  }

  double res = 0.0f;
  for (int i = 1; i <= T; i++)
    res += prob[i][N];
  return res;
}

int main() {
  while (1) {
    int N, T, L, B;
    scanf("%d %d %d %d", &N, &T, &L, &B);
    if (N == 0)
      return 0;
    for (int i = 0; i <= N; i++)
      board[i] = BLANK;
    for (; L > 0; L--) {
      int l;
      scanf("%d", &l);
      board[l] = LOSE;
    }
    for (; B > 0; B--) {
      int b;
      scanf("%d", &b);
      board[b] = BACK;
    }
    printf("%.6f\\n", bp(N, T));
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

const double kProbability = 1.0f / 6.0f;
const int kMaxSquare = 101;
const int kMaxTurn = 101;

enum BoardState { BLANK, LOSE, BACK };

BoardState board[kMaxSquare];

double bp(const int N, const int T) {
  double prob[kMaxTurn][kMaxSquare];
  for (int i = 0; i <= T; i++)
    for (int j = 0; j <= N; j++)
      prob[i][j] = 0.0f;
  prob[0][0] = 1.0f;

  for (int t = 0; t < T; t++) {
    for (int n = 0; n < N; n++) {
      if (prob[t][n] == 0.0f)
        continue;
      for (int dice = 1; dice <= 6; dice++) {
        int pos = (n + dice <= N) ? n + dice : N - (n + dice - N);
        switch (board[pos]) {
        case BLANK:
          prob[t + 1][pos] += prob[t][n] * kProbability;
          break;
        case LOSE:
          prob[t + 2][pos] += prob[t][n] * kProbability;
          break;
        case BACK:
          prob[t + 1][0] += prob[t][n] * kProbability;
        }
      }
    }
  }

  double res = 0.0f;
  for (int i = 1; i <= T; i++)
    res += prob[i][N];
  return res;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  while (1) {
    int N, T, L, B;
    std::cin >> N >> T >> L >> B;
    if (N == 0)
      return 0;
    for (int i = 0; i <= N; i++)
      board[i] = BLANK;
    for (int i = 0; i < L; i++) {
      int l;
      std::cin >> l;
      board[l] = LOSE;
    }
    for (int i = 0; i < B; i++) {
      int b;
      std::cin >> b;
      board[b] = BACK;
    }

    printf("%.6f\\n", bp(N, T));
  }
}
Problem p00856 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int N, T, L, B;
int mass[105];
ld prob = ld(1.0) / 6;
ld cp[105][105];

ld dfs(int s, int t, bool wt) {
  if (s == N)
    return 1.0;
  if (t <= 0)
    return 0;
  if (mass[s] == -1 and wt)
    return dfs(s, t - 1, false);
  if (mass[s] == -2)
    return dfs(0, t, true);
  if (cp[s][t] != -1)
    return cp[s][t];
  ld p = 0.0;
  if (s > N - 6) {
    int left = N - s;
    REP(i, left) p += prob * dfs(s + i + 1, t - 1, true);
    for (int i = left; i < 6; i++)
      p += prob * dfs(N + left - 1 - i, t - 1, true);
    return cp[s][t] = p;
  }
  REP(i, 6) p += prob * dfs(s + i + 1, t - 1, true);
  return cp[s][t] = p;
}

int main() {
  while (cin >> N >> T >> L >> B and N + L + T + B) {
    memset(mass, 0, sizeof(mass));
    REP(i, 105) REP(j, 105) cp[i][j] = -1;
    int tmp;
    REP(i, L) {
      cin >> tmp;
      mass[tmp] = -1;
    }
    REP(i, B) {
      cin >> tmp;
      mass[tmp] = -2;
    }
    cout << setprecision(10) << fixed;
    cout << dfs(0, T, true) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int N, T, L, B;
int mass[105];
ld prob = ld(1.0) / 6;

ld dfs(int s, int t, bool wt) {
  if (s == N)
    return 1.0;
  if (t <= 0)
    return 0;
  if (mass[s] == -1 and wt)
    return dfs(s, t - 1, false);
  if (mass[s] == -2)
    return dfs(0, t, true);
  ld p = 0.0;
  if (s > N - 6) {
    int left = N - s;
    REP(i, left) p += prob * dfs(s + i + 1, t - 1, true);
    for (int i = left; i < 6; i++)
      p += prob * dfs(N + left - 1 - i, t - 1, true);
    return p;
  }
  REP(i, 6) p += prob * dfs(s + i + 1, t - 1, true);
  return p;
}

int main() {
  while (cin >> N >> T >> L >> B and N + L + T + B) {
    memset(mass, 0, sizeof(mass));
    int tmp;
    REP(i, L) {
      cin >> tmp;
      mass[tmp] = -1;
    }
    REP(i, B) {
      cin >> tmp;
      mass[tmp] = -2;
    }
    cout << setprecision(10) << fixed;
    cout << dfs(0, T, true) << endl;
  }
  return 0;
}
Problem p00856 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
  while (1) {
    int n, t, l, b;
    cin >> n >> t >> l >> b;
    if (!n)
      break;

    vector<int> type(n + 1);
    loop(l, i) {
      int j;
      cin >> j;
      type[j] = 1;
    }
    loop(b, i) {
      int j;
      cin >> j;
      type[j] = 2;
    }

    vector<vector<double>> prob(t + 1, vector<double>(n + 1));
    vector<vector<double>> lprob(t + 1, vector<double>(n + 1));
    prob[0][0] = 1;

    loop(t, i) {
      loop(n, j) {
        if (type[j] == 1) {
          lprob[i + 1][j] += prob[i][j] * 6;
        }
        loop(6, k) {
          int idx = j + k + 1;
          if (idx > n)
            idx = n - (idx - n);
          if (type[idx] == 2)
            idx = 0;
          double p = prob[i][j];
          if (type[j] == 1)
            p = lprob[i][j];
          prob[i + 1][idx] += p;
        }
      }
      prob[i + 1][n] += prob[i][n] * 6;
    }

    double ans = 0;
    double sum = 0;
    loop(n + 1, j) sum += prob[t][j] + lprob[t][j];
    ans += prob[t][n] / sum;
    cout << setprecision(9) << fixed;
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
  while (1) {
    int n, t, l, b;
    cin >> n >> t >> l >> b;
    if (!n)
      continue;

    vector<int> type(n + 1);
    loop(l, i) {
      int j;
      cin >> j;
      type[j] = 1;
    }
    loop(b, i) {
      int j;
      cin >> j;
      type[j] = 2;
    }

    vector<vector<double>> prob(t + 1, vector<double>(n + 1));
    vector<vector<double>> lprob(t + 1, vector<double>(n + 1));
    prob[0][0] = 1;

    loop(t, i) {
      loop(n, j) {
        if (type[j] == 1) {
          lprob[i + 1][j] += prob[i][j] * 6;
        }
        loop(6, k) {
          int idx = j + k + 1;
          if (idx > n)
            idx = n - (idx - n);
          if (type[idx] == 2)
            idx = 0;
          double p = prob[i][j];
          if (type[j] == 1)
            p = lprob[i][j];
          prob[i + 1][idx] += p;
        }
      }
      prob[i + 1][n] += prob[i][n] * 6;
    }

    cout << setprecision(9);
    loop(t + 1, j) {
      double total = 0;
      loop(n + 1, i) {
        cout << "[" << i << "] ";
        cout << prob[j][i] << ", ";
        total += prob[j][i];
      }
      cout << lprob[j][2] << endl;
      cout << total + lprob[j][2] << endl;
    }
    double ans = 0;
    double sum = 0;
    loop(n + 1, j) sum += prob[t][j] + lprob[t][j];
    ans += prob[t][n] / sum;
    cout << ans << endl;
  }
  return 0;
}
Problem p00856 (C++) — buggy submission, verdict: Runtime Error

#include "math.h"
#include "stdio.h"

#include <algorithm>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16>>(x) << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define if_range(x, y, w, h) if (0 <= x && x < w && 0 <= y && y < h)

const int INF = 10000000;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;

/** Problem1277 : Minimal Backgammon (途中)**/
char board[110];
int N, T, L, B;
double dp[110][110];

int main() {
  while (cin >> N >> T >> L >> B, N || T || L || B) {
    fill(board, board + 110, ' ');
    fill(dp[0], dp[0] + 110 * 110, 0.0);

    rep(k, L) {
      int x;
      cin >> x;
      board[x] = 'L';
    }

    rep(k, B) {
      int x;
      cin >> x;
      board[x] = 'B';
    }

    dp[0][0] = 1.0;

    rep(t, T) {
      rep(n, N) {
        REP(i, 1, 7) {
          if (dp[t][n] == 0)
            continue;

          int nn = n + i;
          if (nn > N)
            nn = N - (nn - N);
          if (board[nn] == 'B')
            nn = 0;
          dp[t + 1 + (board[nn] == 'L')][nn] += dp[t][n] * (1.0 / 6.0);
        }
      }
    }

    double ans = 0;
    rep(i, T + 1) { ans += dp[i][N]; }
    printf("%.6f\\n", ans);
  }
}

Error: 0

Fixed submission:

#include "math.h"
#include "stdio.h"

#include <algorithm>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16>>(x) << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define if_range(x, y, w, h) if (0 <= x && x < w && 0 <= y && y < h)

const int INF = 10000000;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;

/** Problem1277 : Minimal Backgammon (途中)**/
char board[101];
int N, T, L, B;
double dp[100][100];

int main() {
  while (cin >> N >> T >> L >> B, N || T || L || B) {
    fill(board, board + 100, ' ');
    fill(dp[0], dp[0] + 100 * 100, 0.0);

    rep(k, L) {
      int x;
      cin >> x;
      board[x] = 'L';
    }

    rep(k, B) {
      int x;
      cin >> x;
      board[x] = 'B';
    }

    dp[0][0] = 1.0;

    rep(t, T) {
      rep(n, N) {
        REP(i, 1, 7) {
          if (dp[t][n] == 0)
            continue;

          int nn = n + i;
          if (nn > N)
            nn = N - (nn - N);
          if (board[nn] == 'B')
            nn = 0;
          dp[t + 1 + (board[nn] == 'L')][nn] += dp[t][n] * (1.0 / 6.0);
        }
      }
    }

    double ans = 0;
    rep(i, T + 1) { ans += dp[i][N]; }
    printf("%.6f\\n", ans);
  }
}