alexjercan/bugnet huggingface dataset:
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;

int memo[500][500];

bool check(string str, int start) {
  bool flag = false;

  if (str.empty() == true) {
    flag = true;
  } else {
    if (memo[start][str.size()] == 1) {
      return true;
    } else if (memo[start][str.size()] == 0) {
      return false;
    } else {
      if (str.front() == 'm' && str.back() == 'w') {
        for (int i = 0; i < str.size(); i++) {
          if (str[i] == 'e') {
            if (check(str.substr(1, i - 1), start + 1) &&
                check(str.substr(i + 1, str.size() - i - 2), start + i + 1)) {
              flag = true;
              break;
            }
          }
        }
      }
    }
  }

  if (flag == true) {
    memo[start][str.size()] = 1;
  } else {
    memo[start][str.size()] = 0;
  }

  return flag;
}

int main() {
  for (int i = 0; i < 500; i++) {
    for (int j = 0; j < 500; j++) {
      memo[i][j] = -1;
    }
  }

  string S;
  cin >> S;

  bool flag = check(S, 0);

  if (flag == true) {
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

bool check(string str) {
  bool flag = false;

  if (str.empty() == true) {
    flag = true;
  } else {
    if (str.front() == 'm' && str.back() == 'w') {
      for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'e') {
          if (check(str.substr(1, i - 1)) &&
              check(str.substr(i + 1, str.size() - i - 2))) {
            flag = true;
            break;
          }
        }
      }
    }
  }

  return flag;
}

int main() {
  string S;
  cin >> S;

  bool flag = check(S);

  if (flag == true) {
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }

  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;

// CAT := "" | "m" + CAT + "e" + CAT + "w"

// s[l..r) が CAT かどうか返す.
bool is_cat(const string &s, int l, int r) {
  if (l >= r)
    return true;
  if (s[l] != 'm' || s[r - 1] != 'w')
    return false;

  int k = 0, deep = 0;
  for (int i = l + 1; i < r - 1; i++) {
    if (deep == 0 && s[i] == 'e') {
      k = i;
      break;
    }
    if (s[i] == 'm')
      deep++;
    if (s[i] == 'w')
      deep--;
    if (deep < 0)
      return false;
  }
  return is_cat(s, l + 1, k) && is_cat(s, k + 1, r - 1);
}

int main() {
  string s;
  cin >> s;
  cout << (is_cat(s, 0, s.size()) ? "Cat" : "Rabbit") << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

bool is_cat(const string &s) {
  int N = s.size();
  if (N == 0)
    return true;
  if (s[0] != 'm')
    return false;
  if (s[N - 1] != 'w')
    return false;

  for (int i = 1; i < N; i++) {
    if (s[i] == 'e') {
      // "m" + s[1 .. i-1] + "e" + s[i+1 .. N-2] + "w";
      string a = s.substr(1, i - 1);
      string b = s.substr(i + 1, N - 2 - i);
      if (is_cat(a) && is_cat(b)) {
        return true;
      }
    }
  }
  return false;
}

int main() {
  string s;
  while (cin >> s) {
    bool ans = true;
    if (s.size() % 3 != 0)
      ans = false;
    char f[256] = {0};
    for (int i = 0; i < s.size(); i++) {
      f[s[i]]++;
    }
    if (!(f['m'] == f['e'] && f['e'] == f['w']))
      ans = false;

    if (!ans) {
      cout << "Rabbit" << endl;
    } else {
      cout << (is_cat(s) ? "Cat" : "Rabbit") << endl;
    }
  }
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>

using namespace std;

map<string, bool> m;

bool check(string s) {
  if (m[s]) {
    return false;
  }

  if (s == "") {
    return true;
  }

  int len = (int)s.size();
  if (s[0] != 'm' || s[len - 1] != 'w') {
    m[s] = true;
    return false;
  }

  if (len < 3) {
    m[s] = true;
    return false;
  }

  len = (int)s.size();
  s.erase(--s.end());
  s.erase(s.begin());

  for (int i = 0; i < len; i++) {
    if (s[i] == 'e') {
      string X = s.substr(0, i);
      string Y = s.substr(i + 1, len);

      int ok = 2;
      if (check(X)) {
        ok--;
      } else {
        m[X] = true;
      }

      if (check(Y)) {
        ok--;
      } else {
        m[Y] = true;
      }

      if (!ok) {
        return true;
      }
    }
  }

  m[s] = true;
  return false;
}

int main() {
  string s;

  cin >> s;
  if (check(s)) {
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>

using namespace std;

map<string, bool> m;

bool check(string s) {
  if (m[s]) {
    return false;
  }

  if (s == "") {
    return true;
  }

  int len = (int)s.size();
  if (s[0] != 'm' || s[len - 1] != 'w') {
    m[s] = true;
    return false;
  }

  s.erase(--s.end());
  s.erase(s.begin());
  len = (int)s.size();

  for (int i = 0; i < len; i++) {
    if (s[i] == 'e') {
      string X = s.substr(0, i);
      string Y = s.substr(i + 1);

      if (check(X) && check(Y)) {
        return true;
      }
    }
  }

  m[s] = true;
  return false;
}

int main() {
  string s;

  cin >> s;
  if (check(s)) {
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }

  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;

string s;
bool decided[501][501];
bool dp[501][501];

// s[l, r)???cat??????true?????????
bool isCat(int l, int r) {
  if (decided[l][r]) {
    return dp[l][r];
  }
  if (l == r) {
    dp[l][r] = true;
    decided[l][r] = true;
    return true;
  }
  if (s[l] != 'm') {
    dp[l][r] = false;
    decided[l][r] = true;
    return false;
  }
  if (s[r - 1] != 'w') {
    dp[l][r] = false;
    decided[l][r] = true;
    return false;
  }
  for (int i = l + 1; i < r - 1; i++) {
    if (s[i] == 'e') {
      if (isCat(l + 1, i) && isCat(i + 1, r - 1)) {
        dp[l][r] = true;
        decided[l][r] = true;
        return true;
      }
    }
  }
  dp[l][r] = false;
  decided[l][r] = true;
  return false;
}

int main() {
  cin >> s;
  if (isCat(0, s.length())) {
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

string s;
bool decided[501][501];
bool dp[501][501];

// s[l, r)???cat??????true?????????
bool isCat(int l, int r) {
  if (decided[l][r]) {
    return dp[l][r];
  }
  if (l == r) {
    dp[l][r] = true;
    return true;
  }
  if (s[l] != 'm') {
    dp[l][r] = false;
    return false;
  }
  if (s[r - 1] != 'w') {
    dp[l][r] = false;
    return false;
  }
  for (int i = l + 1; i < r - 1; i++) {
    if (s[i] == 'e') {
      if (isCat(l + 1, i) && isCat(i + 1, r - 1)) {
        dp[l][r] = true;
        return true;
      }
    }
  }
  dp[l][r] = false;
  return false;
}

int main() {
  cin >> s;
  if (isCat(0, s.length())) {
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }
  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <string>
using namespace std;

map<string, bool> memo;

bool cat(string s) {
  if (s.empty())
    return true;
  if (memo.find(s) != memo.end())
    return memo[s];
  int n = s.size() - 1;
  if (s[0] != 'm' || s[n] != 'w')
    return false;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'e') {
      if (cat(s.substr(1, i - 1)) && cat(s.substr(i + 1, n - i - 1)))
        return memo[s] = true;
    }
  }
  return memo[s] = false;
}

int main() {
  string s;
  cin >> s;
  cout << (cat(s) ? "Cat" : "Rabbit") << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

bool cat(string s) {
  if (s.empty())
    return true;
  int n = s.size() - 1;
  if (s[0] != 'm' || s[n] != 'w')
    return false;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'e') {
      if (cat(s.substr(1, i - 1)) && cat(s.substr(i + 1, n - i - 1)))
        return true;
    }
  }
  return false;
}

int main() {
  string s;
  cin >> s;
  cout << (cat(s) ? "Cat" : "Rabbit") << endl;
}
Problem p01486 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
#include <string>
using namespace std;

int cat(string str) {
  stack<int> stk;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == 'm')
      stk.push(0);
    else if (str[i] == 'e')
      stk.push(1);
    else if (str[i] == 'w') {
      if (stk.empty())
        return false;
      if (stk.top() == 1)
        stk.pop();
      else
        return false;
      if (stk.top() == 0)
        stk.pop();
      else
        return false;
      if (stk.empty() && i != str.size() - 1)
        return false;
    }
  }
  if (stk.empty())
    return true;
  return false;
}
int main() {
  string str;
  cin >> str;
  if (cat(str) == true)
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>
#include <string>
using namespace std;
int cat(string str) {
  stack<int> stk;

  for (int i = 0; i < str.size(); i++) {
    if (str[i] == 'm')
      stk.push(0);
    else if (str[i] == 'e')
      stk.push(1);
    else if (str[i] == 'w') {
      if (stk.top() == 1)
        stk.pop();
      else
        return false;
      if (stk.top() == 0)
        stk.pop();
      else
        break;
      if (stk.size() == 0 && i != str.size() - 1)
        return false;
    }
  }
  if (stk.size() == 0)
    return true;
  return false;
}
int main() {
  string str;
  cin >> str;

  if (cat(str) == true)
    cout << "Cat" << endl;
  else
    cout << "Rabit" << endl;

  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string s;
int memo[505][505];

bool dfs(int l, int r) {
  if (l > r)
    return true;
  if (memo[l][r] != -1)
    return memo[l][r];

  if (s[l] == 'm' && s[r] == 'w') {
    REP(i, l + 1, r) {
      if (s[i] == 'e') {
        if (dfs(l + 1, i - 1) && dfs(i + 1, r - 1)) {
          return memo[l][r] = true;
        }
      }
    }
  }
  return memo[l][r] = false;
}

int main() {
  cin >> s;
  memset(memo, -1, sizeof(memo));

  if (dfs(0, s.size() - 1)) {
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string s;

bool dfs(int l, int r) {
  if (l > r)
    return true;

  // cout << " -- in dfs --- :" << l << " " << r << " :";
  // REP(i, l, r+1) {
  // 	cout << s[i];
  // }
  // cout << endl;

  if (s[l] == 'm' && s[r] == 'w') {
    REP(i, l + 1, r) {
      if (s[i] == 'e') {
        if (dfs(l + 1, i - 1) && dfs(i + 1, r - 1)) {
          return true;
        }
      }
    }
  }
  return false;
}

int main() {
  cin >> s;

  if (dfs(0, s.size() - 1)) {
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }

  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

string s;
map<string, bool> mem;

bool ok(string s) {
  int n = s.length();
  if (n == 0)
    return true;
  if (s[0] != 'm' || s[n - 1] != 'w')
    return false;
  if (mem.find(s) != mem.end())
    return mem[s];
  rep(i, n) {
    if (s[i] == 'e') {
      if (ok(s.substr(1, i - 1)) && ok(s.substr(i + 1, n - i - 2)))
        return mem[s] = true;
    }
  }
  return mem[s] = false;
}

int main() {
  cin.sync_with_stdio(false);
  cin >> s;
  if (ok(s))
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

string s;

bool ok(string s) {
  int n = s.length();
  if (n == 0)
    return true;
  if (s[0] != 'm' || s[n - 1] != 'w')
    return false;
  rep(i, n) {
    if (s[i] == 'e') {
      if (ok(s.substr(1, i - 1)) && ok(s.substr(i + 1, n - i - 2)))
        return true;
    }
  }
  return false;
}

int main() {
  cin.sync_with_stdio(false);
  cin >> s;
  if (ok(s))
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;
  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main(void) {
  string s;
  stack<char> c;
  bool w = false;
  getline(cin, s);
  if (s.length() == 0) {
    cout << "Cat" << endl;
    return 0;
  }
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'm' && w) {
      cout << "Rabbit" << endl;
      return 0;
    }
    if (s[i] == 'm')
      c.push('m');
    if (s[i] == 'e') {
      if (c.empty()) {
        cout << "Rabbit" << endl;
        return 0;
      }
      if (c.top() == 'm') {
        c.pop();
        c.push('e');
        w = false;
      } else {
        cout << "Rabbit" << endl;
        return 0;
      }
    }
    if (s[i] == 'w') {
      if (c.empty()) {
        cout << "Rabbit" << endl;
        return 0;
      }
      if (c.top() == 'e') {
        c.pop();
        w = true;
      } else {
        cout << "Rabbit" << endl;
        return 0;
      }
    }
  }
  if (c.empty()) {
    cout << "Cat" << endl;
  } else
    cout << "Rabbit" << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main(void) {
  string s;
  stack<char> c;
  bool w = false;
  getline(cin, s);
  if (s.length() == 0) {
    cout << "Cat" << endl;
    return 0;
  }
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'm' && w) {
      cout << "Rabbit" << endl;
      return 0;
    }
    if (s[i] == 'm')
      c.push('m');
    if (s[i] == 'e') {
      if (c.top() == 'm') {
        c.pop();
        c.push('e');
        w = false;
      } else {
        cout << "Rabbit" << endl;
        return 0;
      }
    }
    if (s[i] == 'w') {
      if (c.top() == 'e') {
        c.pop();
        w = true;
      } else {
        cout << "Rabbit" << endl;
        return 0;
      }
    }
  }
  if (c.empty()) {
    cout << "Cat" << endl;
  } else
    cout << "Rabbit" << endl;
  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>

std::vector<std::vector<int>> memo;

bool is_cat(const std::string &s, size_t il, size_t ir) {
  if (memo[il][ir] > -1)
    return memo[il][ir];

  // fprintf(stderr, "\\"%s\\"[%zu:%zu] (\\"%s\\")\\n", s.c_str(), il, ir,
  // s.substr(il, ir-il).c_str());
  int &res = memo[il][ir];
  if (il == ir)
    return (res = 1);
  if ((ir - il) % 3 > 0)
    return (res = 0);
  if (!(s[il] == 'm' && s[ir - 1] == 'w'))
    return (res = 0);

  for (size_t i = il + 1; i + 1 < ir; i += 3) {
    if (s[i] != 'e')
      continue;
    if (is_cat(s, il + 1, i) && is_cat(s, i + 1, ir - 1))
      return (res = 1);
  }
  return (res = 0);
}

int main() {
  char buf[512];
  scanf("%s", buf);
  std::string s = buf;

  if (s.length() % 3 > 0)
    return !printf("Rabbit\\n");

  memo.assign(s.length() + 1, std::vector<int>(s.length() + 1, -1));
  printf("%s\\n", is_cat(s, 0, s.length()) ? "Cat" : "Rabbit");
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <string>

bool is_cat(const std::string &s, size_t il, size_t ir) {
  if (il == ir)
    return true;
  if ((ir - il) % 3 > 0)
    return false;
  if (!(s[il] == 'm' && s[ir - 1] == 'w'))
    return false;

  for (size_t i = il + 1; i + 1 < ir; i += 3) {
    if (s[i] != 'e')
      continue;
    if (is_cat(s, il + 1, i) && is_cat(s, i + 1, ir - 1))
      return true;
  }
  return false;
}

int main() {
  char buf[512];
  scanf("%s", buf);
  std::string s = buf;

  if (s.length() % 3 > 0)
    return !printf("Rabbit\\n");

  printf("%s\\n", is_cat(s, 0, s.length()) ? "Cat" : "Rabbit");
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cassert>
#include <cstdlib>
#include <iostream>
using namespace std;
string s;
int pos;

bool CAT() {

  if (s[pos] == 'm') {
    pos++;
    if (s[pos] != 'e') {
      bool ok = CAT();
      if (!ok)
        return false;
    }
  }
  if (s[pos] == 'e') {
    pos++;
    if (s[pos] != 'w') {
      bool ok = CAT();
      if (!ok)
        return false;
    }
  }
  if (s[pos] == 'w') {
    pos++;
    return true;
  }

  return false;
}

int main() {

  while (cin >> s) {
    pos = 0;
    if (/*rec(0,s.length()-1)*/ (CAT() && pos == s.length()) || s.length() == 0)
      cout << "Cat" << endl;
    else
      cout << "Rabbit" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>

using namespace std;
string s;
bool rec(int st, int ed) {
  if (s.substr(st, ed - st + 1) == "mew")
    return true;
  if (!(s[st] == 'm' && s[ed] == 'w'))
    return false;
  if (ed - st == 2 && s[st + 1] == 'e')
    return true;
  else if (ed - st == 2 && s[st + 1] != 'e')
    return false;

  for (int i = st; i <= ed; i++) {
    if (s[i] == 'e') {

      if (rec(st + 1, i - 1) || rec(i + 1, ed - 1))
        return true;
    }
  }
  return false;
}

int main() {

  while (cin >> s) {
    if (rec(0, s.length() - 1) || s.length() == 0)
      cout << "Cat" << endl;
    else
      cout << "Rabbit" << endl;
  }
  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

bool dfs(string s) {
  int res = 0;
  if (!s.size())
    return 1;
  if (s[0] != 'm' || s[s.size() - 1] != 'w')
    return 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'e')
      continue;
    string a = s.substr(1, i - 1);
    string b = s.substr(i + 1);
    b.erase(b.end() - 1);
    if (dfs(a) && dfs(b))
      return 1;
  }
  return 0;
}

int main() {
  string s;
  cin >> s;

  while (1) {
    if (s.empty()) {
      puts("Cat");
      break;
    }

    string::size_type p = s.find("mew");
    if (p == string::npos) {
      puts("Rabbit");
      break;
    } else {
      if (!(s.size() == 3 || (s[p - 1] == 'm' && s[p + 3] == 'e') ||
            (s[p - 1] == 'e' && s[p + 3] == 'w'))) {
        puts("Rabbit");
        break;
      }
      s.erase(p, 3);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

bool dfs(string s) {
  int res = 0;
  if (!s.size())
    return 1;
  if (s[0] != 'm' || s[s.size() - 1] != 'w')
    return 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'e')
      continue;
    string a = s.substr(1, i - 1);
    string b = s.substr(i + 1);
    b.erase(b.end() - 1);
    if (dfs(a) && dfs(b))
      return 1;
  }
  return 0;
}

int main() {
  string s;
  cin >> s;
  puts(dfs(s) ? "Cat" : "Rabbit");
  return 0;
}
Problem p01486 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
// #define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
map<string, bool> mp;

bool iscat(string s) {
  auto itr = mp.find(s);
  if (itr != mp.end())
    return mp[s];
  if (s == "")
    return true;
  if (s[0] == 'm' && s[s.size() - 1] == 'w') {
    // find e
    string ns = s.substr(1, s.size() - 2);
    // if(ns[0] == 'm' && ns[ns.size()-1] == 'w') return iscat(ns);
    REP(i, ns.size()) {
      if (ns[i] == 'e') { // 0 1 2 3 4 5 ns.size() = 6 i = 2
        string lstr = ns.substr(0, i);
        string rstr = ns.substr(i + 1, ns.size() - i - 1);
        if (iscat(lstr) && iscat(rstr)) {
          mp[s] = true;
          return true;
        }
      }
    }
    mp[s] = false;
    return false;
  } else {
    return false;
  }
  // dummy
  return false;
}
int main() {
  string s;
  cin >> s;
  if (iscat(s))
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
// #define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
map<string, int> mp;

bool iscat(string s) {
  auto itr = mp.find(s);
  if (itr != mp.end())
    return true;
  if (s == "")
    return true;
  if (s[0] == 'm' && s[s.size() - 1] == 'w') {
    // find e
    string ns = s.substr(1, s.size() - 2);
    REP(i, ns.size()) {
      bool ikkodemo = false;
      if (ns[i] == 'e') { // 0 1 2 3 4 5 ns.size() = 6 i = 2
        string lstr = ns.substr(0, i);
        string rstr = ns.substr(i + 1, ns.size() - i - 1);
        if (iscat(lstr) && iscat(rstr))
          ikkodemo = true;
      }
      if (ikkodemo) {
        mp[s] = 1;
        return true;
      }
    }
  } else {
    return false;
  }
  // dummy
  return false;
}
int main() {
  string s;
  cin >> s;
  if (iscat(s))
    cout << "Cat" << endl;
  else
    cout << "Rabbit" << endl;
}