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

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char room[5][5] = {{1, 1, 1, 1, 1},
                   {1, 0, 0, 0, 1},
                   {1, 0, 0, 0, 1},
                   {1, 0, 0, 0, 1},
                   {1, 1, 1, 1, 1}};

void solve(char n, double m[5][5]) {
  for (; n > 0; n--) {
    double tmp[5][5] = {0};

    for (int y = 1; y <= 3; y++) {
      for (int x = 1; x <= 3; x++) {
        if (m[y][x] > 0.0) {
          for (int i = 0; i < 4; i++) {
            int mx = x + dx[i];
            int my = y + dy[i];
            if (room[my][mx] == 0) {
              tmp[my][mx] += m[y][x] / 4.0;
            } else {
              tmp[y][x] += m[y][x] / 4.0;
            }
          }
          // m[y][x] = 0;
        }
      }
    }
    for (int y = 1; y <= 3; y++) {
      for (int x = 1; x <= 3; x++) {
        m[y][x] = tmp[y][x];
      }
    }
  }
}

int main() {
  char fx[256] = {0}, fy[256] = {0};
  int n;
  char s, t, b;

  for (int i = 0; i < 9; i++) {
    fx[i + 'A'] = i % 3 + 1;
    fy[i + 'A'] = i / 3 + 1;
  }

  while (scanf("%d", &n), n) {
    scanf(" %c %c %c ", &s, &t, &b);
    // cin >> s >> t >> b;
    double m[5][5] = {0};
    for (int i = 1; i <= 3; i++) {
      for (int j = 1; j <= 3; j++) {
        room[i][j] = 0;
        // m[i][j] = 0;
      }
    }

    room[fy[b]][fx[b]] = 1;
    m[fy[s]][fx[s]] = 1.0;

    solve(n, m);

    // debug( m );
    printf("%.9f\\n", m[fy[t]][fx[t]]);
  }
}

Error: WA

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char room[5][5] = {{1, 1, 1, 1, 1},
                   {1, 0, 0, 0, 1},
                   {1, 0, 0, 0, 1},
                   {1, 0, 0, 0, 1},
                   {1, 1, 1, 1, 1}};

/*void debug(char m[5][5]){
        printf("debug : \\n");
        for(int y=1 ; y <= 3 ; y++ ){
                for(int x=1 ; x <= 3 ; x++ ){
                        printf("%3d", m[y][x]);
                }
                puts("");
        }
}*/

void solve(char n, char m[5][5]) {
  char m_[5][5] = {0};
  for (; n; n--) {
    // debug(m);
    for (int y = 1; y <= 3; y++) {
      for (int x = 1; x <= 3; x++) {
        if (m[y][x]) {
          for (int i = 0; i < 4; i++) {
            int mx = x + dx[i];
            int my = y + dy[i];
            if (room[my][mx] == 0) {
              m_[my][mx] += m[y][x];
            }
          }
          m[y][x] = 0;
        }
      }
    }
    for (int y = 1; y <= 3; y++) {
      for (int x = 1; x <= 3; x++) {
        m[y][x] = m_[y][x];
      }
    }
  }
}

int main() {
  char fx[256] = {0}, fy[256] = {0};
  char n, s, t, b;

  for (int i = 0; i < 9; i++) {
    // fx[i+'A']=i%3+1;
    // fy[i+'A']=i/3+1;
  }

  while (scanf("%d ", &n), n) {
    // scanf(" %c %c %c", &s, &t, &b);
    cin >> s >> t >> b;
    char m[5][5] = {0};
    /*for(int i=1 ; i<=3 ; i++){
            for(int j=1 ; j<=3 ; j++){
                    room[i][j] = 0;
                    m[i][j] = 0;
            }
    }

    room[ fy[b] ][ fx[b] ] = 1;
    m[ fy[s] ][ fx[s] ] = 1;*/

    if (n % 2 == 1 && (fy[s] * 3 + fx[s]) % 2 == (fy[t] * 3 + fx[t]) % 2) {
      ;
    } else if (n % 2 == 0 &&
               (fy[s] * 3 + fx[s]) % 2 != (fy[t] * 3 + fx[t]) % 2) {
      ;
    } else {
      // solve( n , m );
      ;
    }
    // debug( m );
    // printf("%.8f\\n" , m[ fy[t] ][ fx[t] ]/pow(4,n));
  }
}