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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e15;

using namespace std;

string S;
/*  solution_1
int ind;
int state = 0;
bool parse(){
  if(ind == S.size()) return false;
  bool ret = true;
  if(S[ind] == 'm'){
    ind++;
    while(S[ind]!='w'){
      state = 1;
      bool tmp = parse();
      if(!tmp) return false;
    }
    ind++;
  }else if(state == 1 && S[ind] == 'e'){
    state = 2;
    ind++;
    ret = true;
  }else if(state == 2 && S[ind] == 'w'){
    state = 0;
    ind++;
    ret = true;
  }else{
    ret = false;
  }
  return ret;
}
*/

// solution_2
int parse(int p) {
  if (S.size() <= p) {
    return -1;
  }

  if (S[p] != 'm') {
    // p = parse(p);
    // if(p==-1 || p >= S.size()) return -1;
    return -1;
  }
  p++;
  if (S[p] != 'e') {
    p = parse(p);
    if (p == -1 || p >= S.size())
      return -1;
  }
  p++;
  if (S[p] != 'w') {
    p = parse(p);
    if (p == -1 || p >= S.size())
      return -1;
  }
  /*
   *????????§???????????????????????????????????¨
   *?????°?????????????????????????????£?????¨???????¬???????????????????????????????
   */
  p++;
  return p;
}

int main() {
  cin >> S;

  /*  solution_1
  ind = 0;
  if(parse() && ind == S.size()) cout<<"Cat"<<endl;
  else cout<<"Rabbit"<<endl;
  */

  // solution_2
  int t = parse(0);
  if (t == S.size())
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e15;

using namespace std;

string S;
/*  solution_1
int ind;
int state = 0;
bool parse(){
  if(ind == S.size()) return false;
  bool ret = true;
  if(S[ind] == 'm'){
    ind++;
    while(S[ind]!='w'){
      state = 1;
      bool tmp = parse();
      if(!tmp) return false;
    }
    ind++;
  }else if(state == 1 && S[ind] == 'e'){
    state = 2;
    ind++;
    ret = true;
  }else if(state == 2 && S[ind] == 'w'){
    state = 0;
    ind++;
    ret = true;
  }else{
    ret = false;
  }
  return ret;
}
*/

// solution_2
int parse(int p) {

  if (S.size() <= p) {
    return -1;
  }

  if (S[p] != 'm') {
    p = parse(p);
    if (p == -1 || p >= S.size())
      return -1;
  }
  p++;
  if (S[p] != 'e') {
    p = parse(p);
    if (p == -1 || p >= S.size())
      return -1;
  }
  p++;
  if (S[p] != 'w') {
    p = parse(p);
    if (p == -1 || p >= S.size())
      return -1;
  }
  /*
   *????????§???????????????????????????????????¨
   *?????°?????????????????????????????£?????¨???????¬???????????????????????????????
   */
  p++;
  return p;
}

int main() {
  cin >> S;

  /*  solution_1
  ind = 0;
  if(parse() && ind == S.size()) cout<<"Cat"<<endl;
  else cout<<"Rabbit"<<endl;
  */

  // solution_2
  int t = parse(0);
  if (t == S.size())
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;

  return 0;
}