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

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>

using namespace std;

int x_move[4] = {0, 0, 1, -1};
int y_move[4] = {1, -1, 0, 0};

struct puzzle {
  int xy[4][6];
  int zero_x;
  int zero_y;
  int count;
};

int go_int(puzzle temp) {
  int sum = 0;
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= 4; j++) {
      sum = sum * 10 + temp.xy[i][j];
    }
  }
  return sum;
}
int syoki[4][6] = {-1, -1, -1, -1, -1, -1, -1, 0,  1,  2,  3,  -1,
                   -1, 4,  5,  6,  7,  -1, -1, -1, -1, -1, -1, -1};

int main() {

  puzzle temp;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 6; j++) {
      temp.xy[i][j] = syoki[i][j];
    }
  }
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= 4; j++) {
      if (temp.xy[i][j] == 0) {
        temp.zero_x = i;
        temp.zero_y = j;
        break;
      }
    }
  }
  temp.count = 0;

  queue<puzzle> BFS;
  map<int, int> m;

  BFS.push(temp);
  m[go_int(temp)] = temp.count;

  while (!BFS.empty()) {
    temp = BFS.front();
    BFS.pop();

    for (int i = 0; i < 4; i++) {
      puzzle temp2 = temp;
      if (temp.xy[temp.zero_x + x_move[i]][temp.zero_y + y_move[i]] != -1) {
        swap(temp2.xy[temp.zero_x + x_move[i]][temp.zero_y + y_move[i]],
             temp2.xy[temp.zero_x][temp.zero_y]);
        temp2.zero_x += x_move[i];
        temp2.zero_y += y_move[i];
        temp2.count++;
        int temp3 = go_int(temp2);
        if (m.count(temp3) == 0) {
          BFS.push(temp2);
          m[temp3] = temp2.count;
        }
      }
    }
  }

  while (cin >> temp.xy[1][1] >> temp.xy[1][2] >> temp.xy[1][3] >>
         temp.xy[1][4] >> temp.xy[2][1] >> temp.xy[2][2] >> temp.xy[2][3] >>
         temp.xy[2][4]) {

    cout << m[go_int(temp)] << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>

using namespace std;

int x_move[4] = {0, 0, 1, -1};
int y_move[4] = {1, -1, 0, 0};

struct puzzle {
  int xy[4][6];
  int zero_x;
  int zero_y;
  int count;
};

int go_int(puzzle temp) {
  int sum = 0;
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= 4; j++) {
      sum = sum * 10 + temp.xy[i][j];
    }
  }
  return sum;
}

int main() {

  puzzle temp;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 6; j++) {
      temp.xy[i][j] = -1;
    }
  }
  while (cin >> temp.xy[1][1] >> temp.xy[1][2] >> temp.xy[1][3] >>
         temp.xy[1][4] >> temp.xy[2][1] >> temp.xy[2][2] >> temp.xy[2][3] >>
         temp.xy[2][4]) {
    for (int i = 1; i <= 2; i++) {
      for (int j = 1; j <= 4; j++) {
        if (temp.xy[i][j] == 0) {
          temp.zero_x = i;
          temp.zero_y = j;
          break;
        }
      }
    }
    temp.count = 0;

    queue<puzzle> BFS;
    bool *m = new bool[76543211];

    BFS.push(temp);
    m[go_int(temp)] = true;

    while (!BFS.empty()) {
      temp = BFS.front();
      BFS.pop();

      if (go_int(temp) == 1234567) {
        break;
      }

      for (int i = 0; i < 4; i++) {
        puzzle temp2 = temp;
        if (temp.xy[temp.zero_x + x_move[i]][temp.zero_y + y_move[i]] != -1) {
          swap(temp2.xy[temp.zero_x + x_move[i]][temp.zero_y + y_move[i]],
               temp2.xy[temp.zero_x][temp.zero_y]);
          temp2.zero_x += x_move[i];
          temp2.zero_y += y_move[i];
          temp2.count++;
          int temp3 = go_int(temp2);
          if (m[temp3] == 0) {
            BFS.push(temp2);
            m[temp3] = true;
          }
        }
      }
    }
    cout << temp.count << endl;
  }
}