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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>

#define vc vector<char>
#define C vector<vc>

C c;

vc r90(vc v) {
  vc r;
  rep(i, 3) for (int j = 2; j >= 0; j--) r.pb(v[j * 3 + i]);
  return r;
}

vc l90(vc v) {
  vc r;
  for (int i = 2; i >= 0; i--)
    rep(j, 3) r.pb(v[j * 3 + i]);
  return r;
}

vc r180(vc v) {
  vc r;
  for (int i = 2; i >= 0; i--)
    for (int j = 2; j >= 0; j--)
      r.pb(v[i * 3 + j]);
  return r;
}

C rotf(C c) {
  C r;
  r.pb(c[5]);
  r.pb(r90(c[1]));
  r.pb(r180(c[4]));
  r.pb(l90(c[3]));
  r.pb(c[0]);
  r.pb(r180(c[2]));
  return r;
}

C rotr(C c) {
  C r;
  r.pb(r90(c[0]));
  r.pb(r90(c[4]));
  r.pb(l90(c[2]));
  r.pb(r90(c[5]));
  r.pb(r90(c[3]));
  r.pb(r90(c[1]));
  return r;
}

C rotba(C c) {
  C r;
  r.pb(c[4]);
  r.pb(l90(c[1]));
  r.pb(r180(c[5]));
  r.pb(r90(c[3]));
  r.pb(r180(c[2]));
  r.pb(c[0]);
  return r;
}

C rotl(C c) {
  C r;
  r.pb(l90(c[0]));
  r.pb(l90(c[5]));
  r.pb(r90(c[2]));
  r.pb(l90(c[4]));
  r.pb(l90(c[1]));
  r.pb(l90(c[3]));
  return r;
}

int main() {
  c.resize(6);
  rep(i, 6) c[i].resize(9);
  while (cin >> c[0][0]) {
    if (c[0][0] == '#')
      break;
    rep(i, 8) cin >> c[0][i + 1];
    rep(i, 5) rep(j, 9) cin >> c[i + 1][j];
    map<C, int> M;
    queue<C> Q;
    M[c] = 0;
    Q.push(c);
    while (1) {
      C c = Q.front();
      Q.pop();
      int s = M[c];
      if ((c[0][6] == '*' || c[0][7] == '*' || c[0][8] == '*') &&
          (c[2][6] == '*' || c[2][7] == '*' || c[2][8] == '*')) {
        cout << s << endl;
        break;
      }
      C c0 = rotf(c), c1 = rotr(c), c2 = rotba(c), c3 = rotl(c);
      if (M.find(c0) == M.end())
        M[c0] = s + 1, Q.push(c0);
      if (M.find(c1) == M.end())
        M[c1] = s + 1, Q.push(c1);
      if (M.find(c2) == M.end())
        M[c2] = s + 1, Q.push(c2);
      if (M.find(c3) == M.end())
        M[c3] = s + 1, Q.push(c3);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>

#define vc vector<char>
#define C vector<vc>

C c;
map<C, int> M;

vc r90(vc v) {
  vc r;
  rep(i, 3) for (int j = 2; j >= 0; j--) r.pb(v[j * 3 + i]);
  return r;
}

vc l90(vc v) {
  vc r;
  for (int i = 2; i >= 0; i--)
    rep(j, 3) r.pb(v[j * 3 + i]);
  return r;
}

vc r180(vc v) {
  vc r;
  for (int i = 2; i >= 0; i--)
    for (int j = 2; j >= 0; j--)
      r.pb(v[i * 3 + j]);
  return r;
}

C rotf(C c) {
  C r;
  r.pb(c[5]);
  r.pb(r90(c[1]));
  r.pb(r180(c[4]));
  r.pb(l90(c[3]));
  r.pb(c[0]);
  r.pb(r180(c[2]));
  return r;
}

C rotr(C c) {
  C r;
  r.pb(r90(c[0]));
  r.pb(r90(c[4]));
  r.pb(l90(c[2]));
  r.pb(r90(c[5]));
  r.pb(r90(c[3]));
  r.pb(r90(c[1]));
  return r;
}

C rotba(C c) {
  C r;
  r.pb(c[4]);
  r.pb(l90(c[1]));
  r.pb(r180(c[5]));
  r.pb(r90(c[3]));
  r.pb(r180(c[2]));
  r.pb(c[0]);
  return r;
}

C rotl(C c) {
  C r;
  r.pb(l90(c[0]));
  r.pb(l90(c[5]));
  r.pb(r90(c[2]));
  r.pb(l90(c[4]));
  r.pb(l90(c[1]));
  r.pb(l90(c[3]));
  return r;
}

int main() {
  c.resize(6);
  rep(i, 6) c[i].resize(9);
  while (cin >> c[0][0]) {
    if (c[0][0] == '#')
      break;
    rep(i, 8) cin >> c[0][i + 1];
    rep(i, 5) rep(j, 9) cin >> c[i + 1][j];
    queue<C> Q;
    M[c] = 0;
    Q.push(c);
    while (1) {
      C c = Q.front();
      Q.pop();
      int s = M[c];
      if ((c[0][6] == '*' || c[0][7] == '*' || c[0][8] == '*') &&
          (c[2][6] == '*' || c[2][7] == '*' || c[2][8] == '*')) {
        cout << s << endl;
        break;
      }
      C c0 = rotf(c), c1 = rotr(c), c2 = rotba(c), c3 = rotl(c);
      if (M.find(c0) == M.end())
        M[c0] = s + 1, Q.push(c0);
      if (M.find(c1) == M.end())
        M[c1] = s + 1, Q.push(c1);
      if (M.find(c2) == M.end())
        M[c2] = s + 1, Q.push(c2);
      if (M.find(c3) == M.end())
        M[c3] = s + 1, Q.push(c3);
    }
  }
}