Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Problem A:
CatChecker

  外見からねこかどうかわからない動物がいる. あなたは, 鳴き声がねこの鳴き声であればねこであり, そうでなければうさぎであると判定することにした.

  ねこの鳴き声は次のように定義される.

  
 "" (empty string) はねこの鳴き声である.

  
 $X$, $Y$ がねこの鳴き声であれば 'm' + $X$ + 'e' + $Y$ + 'w' は猫の鳴き声である. ただし + は文字列の連結を表す.

  
以上で定義されるものだけがねこの鳴き声である.

BNF で表すとねこの鳴き声 $CAT$ は

$CAT$ := "" (empty string) $|$ 'm' + $CAT$ + 'e' + $CAT$ + 'w'

と定義される.

  鳴き声を表す文字列 $S$ が与えられる. 鳴き声から動物が何であるか判定せよ.

Constraints

    

      $S$ will contain between 1 and 500 characters, inclusive. Each character in $S$ will be 'm', 'e' or 'w'.
      

Input

  入力は以下の形式で与えられる:

  

$S$

Output

$S$ が猫の鳴き声であれば "Cat", そうでなければ "Rabbit" と1 行に出力せよ.

Sample Input 1

mmemewwemeww

Sample Output 1

Cat

Sample Input 2

mewmew

Sample Output 2

Rabbit


Sample input:
mmemewwemeww


Sample output:
Cat

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

S = raw_input()

def func(lst):
    if type(lst) == type(0):
        return True
    if len(lst) > 2:
        return False
    ret = True
    for l in lst:
        ret = (ret or func(l))
    return ret

S = S.replace('mew', '[1]')
S = S.replace('me', 'm[1]e')
S = S.replace('m', '[')
S = S.replace('e', ',')
S = S.replace('w', ']')
print S
try:
    exec('piyo = ' + S)
except:
    print 'Rabbit'
    exit()
if func(piyo):
    print 'Cat'
else:
    print 'Rabbit'

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

S0 = input()

while S0:
    S = S0.replace("mew", "*")
    S = S.replace("m*ew", "*")
    S = S.replace("me*w", "*")
    S = S.replace("m*e*w", "*")
    if S=="*":
        print("Cat")
        break
    if S == S0:
        print("Rabit")
        break
    S0 = S
else:
    print("Rabit")

Submission status: Wrong Answer

Solution code:
S0 = input()
while S0:
    S = S0.replace("mew", "")
    if S == S0:
        print("Rabit")
        break
    S0 = S
else:
    print("Cat")

Submission status: Accepted

Solution code:
s = raw_input()
cur = 0
def parse():
    global cur
    if s[cur] != "m": return 0
    cur += 1
    if s[cur] == "m" and not parse(): return 0
    if s[cur] != "e": return 0
    cur += 1
    if s[cur] == "m" and not parse(): return 0
    if s[cur] != "w": return 0
    cur += 1
    return 1
print "Cat"*(parse() and cur == len(s)) or "Rabbit"

Submission status: Accepted

Solution code:
import re
b=s=input()
while 1:
    s=re.sub(r'(m|e)mew(e|w)','\\1\\2',s)
    if b==s:break
    b=s
print(['Rabbit','Cat'][s=='mew'])

Submission status: Accepted

Solution code:
import re
s=input()
while s!=re.sub(r'(m|e)mew(e|w)','\\1\\2',s):s=re.sub(r'(m|e)mew(e|w)','\\1\\2',s)
print(['Rabbit','Cat'][s=='mew'])

Submission status: Accepted

Solution code:
import re

def delete(s):
  if len(s) < 3: return s
  if s == 'mew': return ''
  res = re.finditer('mew', s, re.MULTILINE)
  for m in res:
    if m.start() == 0: continue
    if m.end() == len(s): continue
    ss = s[:m.start()]+s[m.end():]
    return delete(ss)
  return s

s = raw_input()
ss = delete(s)
if len(ss) == 0: print "Cat"
else: print "Rabbit"

Submission status: Accepted

Solution code:
S = input()
L = len(S)
dp = [[False] * (L + 1) for _ in range(L + 1)]

# [left, right)
for i in range(L + 1):
    dp[i][i] = True

for w in range(3, L + 1):
    for left in range(L - w + 1):
        right = left + w
        if S[left] != 'm' or S[right - 1] != 'w':
            continue
        for mid in range(left + 1, right):
            if S[mid] == 'e' and dp[left + 1][mid] and dp[mid + 1][right - 1]:
                dp[left][right] = True
                break
print("Cat" if dp[0][L] else "Rabbit")

Submission status: Accepted

Solution code:
S = input()
L = len(S)
dp = [[False] * (L + 1) for _ in range(L + 1)]

# [left, right)
for i in range(L + 1):
    dp[i][i] = True

for w in range(3, L + 1, 3):
    for left in range(L - w + 1):
        right = left + w
        if S[left] != 'm' or S[right - 1] != 'w':
            continue
        for mid in range(left + 1, right):
            if S[mid] == 'e' and dp[left + 1][mid] and dp[mid + 1][right - 1]:
                dp[left][right] = True
                break
print("Cat" if dp[0][L] else "Rabbit")

Submission status: Accepted

Solution code:
#!/usr/bin/env python

S = raw_input()

S = S.replace('mew', '[1]')
S = S.replace('me', 'm[1]e')
S = S.replace('ew', 'e[1]w')
S = S.replace('m', '[')
S = S.replace('e', ',')
S = S.replace('w', ']')

for i in range(500):
    S = S.replace('[[1],[1]]', '[1]')

if S == '[1]' or S == '':
    print 'Cat'
else:
    print 'Rabbit'

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    l = len(s)
    d = collections.defaultdict(int)

    m = {}
    m[''] = True
    def f(s):
        if s in m:
            return m[s]
        if s[0] != 'm' or s[-1] != 'w':
            m[s] = False
            return False
        l = len(s)
        for i in range(1,l-1):
            if s[i] != 'e':
                continue
            if f(s[1:i]) and f(s[i+1:-1]):
                m[s] = True
                return True
        m[s] = False
        return False

    if f(s):
        return 'Cat'
    return 'Rabbit'


print(main())

Submission status: Accepted

Solution code:
s = input()
tmp = s
while True:
  s = s.replace("mew", "Y")
  s = s.replace("mXeXw", "Y")
  s = s.replace("meXw", "Y")
  s = s.replace("mXew", "Y")
  s = s.replace("Y", "X")
  if s == tmp:
    if s == "X" or s == "":
      print("Cat")
    else:
      print("Rabbit")
    break
  tmp = s

Submission status: Accepted

Solution code:
cat = ["mew","mcecw","mcew","mecw"]
a = raw_input()
while any(i in a for i in cat):
	a = a.replace("mew","c").replace("mcecw","c").replace("mcew","c").replace("mecw","c")
print "Cat" if a == "c" else "Rabbit"

Submission status: Accepted

Solution code:
cat = ["mew","mcecw","mcew","mecw"]
a = raw_input()
while any(i in a for i in cat):
	for i in cat: a = a.replace(i,"c")
print "Cat" if a == "c" else "Rabbit"

Submission status: Accepted

Solution code:

inf = 1000000007

def check(roar,i):
    if roar[i]!='m':return inf
    i+=1
    if roar[i]=='e':i+=1
    else :
        j = check(roar,i)
        if j==inf:return inf
        i = j+1
    if roar[i]=='w':i+=1
    else :
        j = check(roar,i)
        if j==inf:return inf
        i = j+1
    return i



def main():
    roar = input()
    if check(roar,0)==len(roar):print ('Cat')
    else                       :print ('Rabbit')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**5)

def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LI_(): return [-1*int(x) for x in input().split()]
def II(): return int(input())
def IF(): return float(input())
def LM(func,n): return [[func(x) for x in input().split()]for i in range(n)]
mod = 1000000007
inf = float('INF')

def isCat(S):
    #print(S)
    if len(S) == 0:
        return True
    if S[0] != "m" or S[-1] != "w":
        return False
    c = 0
    i=0
    for i in range(1,len(S)-1):
        if S[i] == 'm':
            c += 1
        elif S[i] == 'w':
            c -= 1
        if c ==0:
            break
    if S[1] == 'e':
        i = 0
    return S[i+1] == 'e' and isCat(S[1:i+1]) and isCat(S[i+2:-1])



if(isCat(input())):
    print("Cat")
else:

    print("Rabbit")

Submission status: Runtime Error

Solution code:

#include <iostream>
#include <regex>

using namespace std;

int main(void){
  string s;
  cin >> s;
  bool isCat = false;
  while(true){
    if(s == "mew"){
      isCat = true;
      break;
    }
    string buf_s = s;
    s = regex_replace(s, regex("mmewe"), "me");
    s = regex_replace(s, regex("emeww"), "ew");
    if(buf_s == s) break;
  }
  if(isCat) cout << "Cat" << endl;
  else cout << "Rabbit" << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

S = raw_input()

def func(lst):
    if type(lst) == type(0):
        return True
    if len(lst) > 2:
        return False
    ret = True
    for l in lst:
        ret = (ret or func(l))
    return ret

S = S.replace('mew', '[1]')
S = S.replace('me', 'm[1]e')
S = S.replace('m', '[')
S = S.replace('e', ',')
S = S.replace('w', ']')

try:
    exec('piyo = ' + S)
except:
    print 'Rabbit'
    exit()
if func(piyo):
    print 'Cat'
else:
    print 'Rabbit'