Problem p01486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define exist(s, e) ((s).find(e) != (s).end())
#define range(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) range(i, 0, n)
#define clr(a, b) memset((a), (b), sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 29;

bool dp[510][510];

int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i <= n; ++i)
    dp[i][i] = true;

  for (int d = 3; d <= n; d += 3) {
    for (int i = 0; i <= n - d; ++i) {
      if (s[i] != 'm')
        continue;
      if (s[i + d - 1] != 'w')
        continue;
      for (int j = i + 1; j < i + d - 1; ++j) {
        if (s[j] != 'e')
          continue;
        dump(d) dump(i) dump(j) dp[i][i + d] |=
            (dp[i + 1][j] && dp[j + 1][i + d - 1]);
      }
    }
  }
  if (dp[0][n])
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define exist(s, e) ((s).find(e) != (s).end())
#define range(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) range(i, 0, n)
#define clr(a, b) memset((a), (b), sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 29;

bool dp[510][510];

int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i <= n; ++i)
    dp[i][i] = true;

  for (int d = 3; d <= n; d += 3) {
    for (int i = 0; i <= n - d; ++i) {
      if (s[i] != 'm')
        continue;
      if (s[i + d - 1] != 'w')
        continue;
      for (int j = i + 1; j < i + d - 1; ++j) {
        if (s[j] != 'e')
          continue;
        dp[i][i + d] |= (dp[i + 1][j] && dp[j + 1][i + d - 1]);
      }
    }
  }
  if (dp[0][n])
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;
  return 0;
}