Problem:


Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO



Sample input:
erasedream


Sample output:
YES

Submission status: Memory Limit Exceeded

Solution code:
S = input()
N = len(S)
op = [""]
while len(op):
    T = op.pop()
    len_T = len(T)
    if S == T:
        print("YES")
        exit(0)
    if len_T - 5 <= N:
        if S[len_T:len_T+5] == "dream":
            op.append(T + "dream")
            if len_T - 7 <= N:
                if S[len_T:len_T+7] == "dreamer":
                    op.append(T + "dreamer")
        if S[len_T:len_T+5] == "erase":
            op.append(T + "erase")
            if len_T - 6 <= N:
                if S[len_T:len_T+6] == "eraser":
                    op.append(T + "eraser")
print("NO")

Submission status: Memory Limit Exceeded

Solution code:
s = input()
youso = ['dream', 'dreamer', 'erase', 'eraser']

ans = False
for word_0 in youso:
  list_ = []
  if s[:len(word_0)]==word_0:
    list_.append(word_0)
    
  while list_:
    kouho = list_.pop()
    if kouho==s:
        ans=True
        break
    
    for word_1 in youso:
      tmp = kouho+word_1
      if s[:len(tmp)]==tmp:
        list_.append(tmp)
        
if ans:
  print('YES')
else:
  print('NO')

Submission status: Memory Limit Exceeded

Solution code:
W = ['dream','dreamer','erase','eraser']
def getNext(s):
    for w in W:
        tmps = s
        if tmps[:len(w)] != w:
            continue
        tmps = tmps[len(w):]
        if len(tmps) == 0:
            return ''
        tmps = getNext(tmps)
        if len(tmps) == 0:
            return ''
    return(s)
            
S = input()
s = getNext(S)
if len(s) == 0:
    print("YES")
else:
    print("NO")

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

S = input()
T = ''
U = ['dreamer', 'dream', 'eraser', 'erase']

answer = 'NO'


def possible(current):
    for s in U:
        if S.startswith(current + s):
            yield s


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES':
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                if len(S) >= len(current + candidate):
                    judge(current + candidate)


judge(T)

print(answer)

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

S = input()
T = ''
U = ['dreamer', 'dream', 'eraser', 'erase']

answer = 'NO'


def possible(current):
    return [s for s in U if S.startswith(current + s)]


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES':
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                if len(S) >= len(current + candidate):
                    judge(current + candidate)


judge(T)

print(answer)

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

S = input()
U = ['dreamer', 'dream', 'eraser', 'erase']

answer = 'NO'


def possible(current):
    return [s for s in U if S.startswith(current + s)]


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES':
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                if len(S) >= len(current + candidate):
                    judge(current + candidate)


judge('')

print(answer)

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

S = input()
U = ['dreamer', 'dream', 'eraser', 'erase']

answer = 'NO'


def possible(current):
    possible = []
    for string in U:
        if S.startswith(current + string):
            possible.append(string)
    return possible


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES':
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                if len(S) >= len(current + candidate):
                    judge(current + candidate)


judge('')

print(answer)

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

S = input()
U = ['dreamer', 'dream', 'eraser', 'erase']

answer = 'NO'


def possible(current):
    possible = []
    for string in U:
        if S.startswith(current + string):
            possible.append(string)
    return possible


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES':
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                new = current + candidate
                if len(S) >= len(new):
                    judge(current + candidate)


judge('')

print(answer)

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4100000)

S = input()
U = ['dreamer', 'dream', 'eraser', 'erase']

answer = 'NO'


def possible(current):
    possible = []
    for string in U:
        if S.startswith(current + string):
            possible.append(string)
    return possible


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES':
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                new = current + candidate
                if len(S) >= len(new):
                    judge(current + candidate)


judge('')

print(answer)

Submission status: Memory Limit Exceeded

Solution code:
def dfs(string):
    can = ["dream", "dreamer", "erase", "eraser"]
    stack = []
    stack.append("dream")
    stack.append("dreamer")
    stack.append("erase")
    stack.append("eraser")
    while stack:
        judge = stack.pop()
        if judge == string:break
        for temp in can:
            ans = judge + temp
            if ans == string[:len(ans)]:
                stack.append(ans)
    return "YES" if judge == string else "NO"

if __name__ == '__main__':
    s = input()
    print(dfs(s))

Submission status: Memory Limit Exceeded

Solution code:
def main():
    from functools import lru_cache
    import sys
    sys.setrecursionlimit(10 ** 7)

    WORDS = 'dream', 'dreamer', 'erase', 'eraser'

    S = input()

    @lru_cache(maxsize=None)
    def dfs(s=S):
        if not s:
            return True

        for word in WORDS:
            if s.endswith(word) and dfs(s[:-len(word)]):
                return True

        return False

    cond = dfs()
    print('YES' if cond else 'NO')


if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

    WORDS = 'dream', 'dreamer', 'erase', 'eraser'

    S = input()

    def dfs(s=S):
        if not s:
            return True

        for word in WORDS:
            if s.endswith(word) and dfs(s[:-len(word)]):
                return True

        return False

    cond = dfs()
    print('YES' if cond else 'NO')


if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

Solution code:
import sys 
sys.setrecursionlimit(10**6)
s = input()
def dfs(t):
    if t==s:
        return True
    if t!=s[:len(t)]:
        return False
    if s[len(t)] == 'd':
        for i in ['dream', 'dreamer']:
            if dfs(t+i):
                return True
    elif s[len(t)]:
        for i in ['erase', 'eraser']:
            if dfs(t+i):
                return True
    else:
        return False
if dfs(''):
    print('YES')
else:
    print('NO')

Submission status: Memory Limit Exceeded

Solution code:
S = input()[::-1]
import sys
sys.setrecursionlimit(100000)
c = ['maerd', 'remaerd', 'esare', 'resare']

def dfs(s):
    l = len(s)
    if l==0:
        return True
    if l<5:
        return False
    if s[:5] in c:
        return dfs(s[5:])
    elif l>=6 and s[:6]=='resare':
        return dfs(s[6:])
    elif l>=7 and s[:7]=='remaerd':
        return dfs(s[7:])
    else:
        return False

if dfs(S):
    print('YES')
else:
    print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(5000)
def func(x):

    if len(x) == 0:
        return True
    elif len(x) < 5:
        return False
    else:
        tmp = False
        if x[-5:] == "dream":
            tmp = func(x[:-5])

        if x[-7:] == "dreamer" and not tmp:
            tmp = func(x[:-7])

        if x[-5:] == "erase" and not tmp:
            tmp = func(x[:-5])

        if x[-6:] == "eraser" and not tmp:
            tmp = func(x[:-6])

    return tmp

def solve(n):

    ans = func(n)
    return "YES" if ans else "NO"

if __name__ == "__main__":
    n = input()
    print(solve(n))

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000)
def func(x):

    if len(x) == 0:
        return True
    elif len(x) < 5:
        return False
    else:
        tmp = False
        if x[:5] == "dream":
            tmp = func(x[5:])

        if x[:7] == "dreamer" and not tmp:
            tmp = func(x[7:])

        if x[:5] == "erase" and not tmp:
            tmp = func(x[5:])

        if x[:6] == "eraser" and not tmp:
            tmp = func(x[6:])

    return tmp

def solve(n):

    ans = func(n)
    return "YES" if ans else "NO"

if __name__ == "__main__":
    n = input()
    print(solve(n))

Submission status: Memory Limit Exceeded

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    S=input()
    n=len(S)
    A="dream dreamer erase eraser".split()
    #print(A)
    global cond
    
    
    que=[S]
    while(que!=[]):
        vS=que.pop()
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])

    print("NO")
#%%submit!
resolve()

Submission status: Memory Limit Exceeded

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    S=input()
    n=len(S)
    A="dream dreamer erase eraser".split()
    #print(A)
    global cond
    cond=[]
    def dfslike_dreameraser(varS):#string->bool,resursion
        #print(varS)
        if len(varS)==0:
            cond.append(1)
            return 
        for word in A:
            if varS[:len(word)]==word:
                dfslike_dreameraser(varS[len(word):])
        return 
        
    dfslike_dreameraser(S)
    #print(cond)
    print(["NO","YES"][cond!=[]])
#%%submit!
resolve()

Submission status: Memory Limit Exceeded

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    S=input()
    n=len(S)
    A="dream dreamer erase eraser".split()
    #print(A)
    global cond
    cond=[]
    def dfslike_dreameraser(varS):#string->bool,resursion
        #print(varS)
        if len(varS)==0:
            cond.append(1)
            return 
        for word in A:
            if varS[:len(word)]==word:
                dfslike_dreameraser(varS[len(word):])
        return 
        
    dfslike_dreameraser(S)
    #print(cond)
    print(["NO","YES"][cond!=[]])
#%%submit!
resolve()

Submission status: Memory Limit Exceeded

Solution code:
def resolve():
    S = input()
    strings = ["dream", "dreamer", "erase", "eraser"]
    import collections
    deq = collections.deque([S])

    while deq:
        s = deq.pop()
        if s == "":
            print("YES")
            return
        for item in strings:
            if s.startswith(item):
                deq.append(s[len(item):])
    print("NO")




if '__main__' == __name__:
    resolve()

Submission status: Memory Limit Exceeded

Solution code:
import sys


def start_with(s):
    if s == '':
        print('YES')
        sys.exit(0)

    try:
        if s[0:5] == 'dream':
            start_with(s[5:])
        if s[0:7] == 'dreamer':
            start_with(s[7:])
        if s[0:5] == 'erase':
            start_with(s[5:])
        if s[0:6] == 'eraser':
            start_with(s[6:])
        return 
    except IndexError:
        return


sys.setrecursionlimit(1000000)
S = input()
start_with(S)
print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys


def start_with(s):
    if s == '':
        print('YES')
        sys.exit(0)

    try:
        if s[0:5] == 'dream':
            start_with(s[5:])
        if s[0:7] == 'dreamer':
            start_with(s[7:])
        if s[0:5] == 'erase':
            start_with(s[5:])
        if s[0:6] == 'eraser':
            start_with(s[6:])
    except IndexError:
        return


sys.setrecursionlimit(1000000)
S = input()
start_with(S)
print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) 
S = input()
T = ""

cand = ["dream", "dreamer", "erase", "eraser"]

def clean_string(s):
    if s == "" :
        print("YES")
        sys.exit()
    if not any([s.startswith(c) for c in cand]):
        return
    
    s_ = s
    for c in cand:
        if s_.startswith(c):
            s = s_[len(c):]
            clean_string(s)
    del s_

clean_string(S)
print("NO")

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8) 
S = input()
T = ""

cand = ["dream", "dreamer", "erase", "eraser"]

def clean_string(s):
    if s == "" :
        print("YES")
        sys.exit()
    if not any([s.startswith(c) for c in cand]):
        return
    
    s_ = s
    for c in cand:
        if s_.startswith(c):
            s = s_[len(c):]
            clean_string(s)

clean_string(S)
print("NO")

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8) 
S = input()
T = ""

cand = ["dream", "dreamer", "erase", "eraser"]

def clean_string(s):
    if s == "" :
        print("YES")
        sys.exit()
    if not any([s.startswith(c) for c in cand]):
        return
    
    for c in cand:
        if s.startswith(c):
            s_next = s[len(c):]
            clean_string(s_next)

clean_string(S)
print("NO")

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) 
S = input()
T = ""

cand = ["dream", "dreamer", "erase", "eraser"]

def clean_string(s):
    if s == "" :
        print("YES")
        sys.exit()
    if not any([s.startswith(c) for c in cand]):
        return
    
    for c in cand:
        if s.startswith(c):
            s_next = s[len(c):]
            clean_string(s_next)

clean_string(S)
print("NO")

Submission status: Memory Limit Exceeded

Solution code:
# 逆から読んでみる
# ちょっと休憩


# def check(string):
#   l = len(string)

#   if l == 0:
#     return True
  
#   if l < 5:
#     return False

#   if string[0:5] == 'dream':
#     if check(string[5:]):
#       return True
#     if l >= 7 and string[0:7] == 'dreamer':
#       if check(string[7:]):
#         return True
#   elif string[0:5] == 'erase':
#     if check(string[5:]):
#       return True
#     if l >= 6 and string[0:6] == 'eraser':
#       if check(string[6:]):
#         return True
  
#   return False

dream = list(reversed('dream'))
dreamer = list(reversed('dreamer'))
erase = list(reversed('erase'))
eraser = list(reversed('eraser'))

def check(string):
  l = len(string)

  if l == 0:
    return True
  
  if l < 5:
    return False

  if string[0:5] == dream:
    return check(string[5:])
  if l >= 7 and string[0:7] == dreamer:
    return check(string[7:])
  if string[0:5] == erase:
    return check(string[5:])
  if l >= 6 and string[0:6] == eraser:
    return check(string[6:])
      
  return False

S = input()
S = list(reversed(S))
if check(S):
  print("YES")
else:
  print("NO")

Submission status: Memory Limit Exceeded

Solution code:
def we_can(s):
    if len(s) == 0:
        return True
    else:
        if s[-5:] == 'dream' or s[-5:] == 'erase':
            if we_can(s[:-5]):
                return True
        elif s[-6:] == 'eraser':
            if we_can(s[:-6]):
                return True
        elif s[-7:] == 'dreamer':
            if we_can(s[:-7]):
                return True
    return False


s = input()
if we_can(s):
    print('YES')
else:
    print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys
#input = sys.stdin.buffer.readline
sys.setrecursionlimit(20000+1)

def main():
    s = "".join(list(reversed(str(input()))))

    def ch(s):
        if len(s) == 0:
            return True
        elif len(s) >= 5:
            use = ["maerd","esare"]
            if s[:5] in use:
                return ch(s[5:])
            elif (len(s) >= 6 and s[:6] == "resare"):
                return ch(s[6:])
            elif (len(s) >= 7 and s[:7] == "remaerd"):
                return ch(s[7:])
            else:
                return False
        else:
            return False
            
    if (ch(s)):
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()

Submission status: Memory Limit Exceeded

Solution code:
def main():
  q=[input()]
  l=["dream","dreamer","erase","eraser"]
  while q:
    s=q.pop()
    if s=="":
      print("YES")
      return
    for i in l:
      n=len(i)
      if s[:n]==i:
        q.append(s[n:])
  print("NO")

main()

Submission status: Memory Limit Exceeded

Solution code:
def main():
    import sys

    sys.setrecursionlimit(10 ** 7)

    def dfs(s):
        if not s: return True

        for w in ('dream', 'dreamer', 'erase', 'eraser'):
            if s.endswith(w) and dfs(s[:-len(w)]):
                return True

        return False

    s = input()
    print('YES' if dfs(s) else 'NO')


if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

Solution code:
def main():
    import sys

    sys.setrecursionlimit(10 ** 7)

    def dfs(s):
        if not s: return True

        for w in ('dream', 'dreamer', 'erase', 'eraser'):
            if s[len(s) - len(w):] == w and dfs(s[:len(s) - len(w)]):
                return True

        return False

    s = input()
    print('YES' if dfs(s) else 'NO')


if __name__ == '__main__':
    main()

Submission status: Memory Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**5)

def isdreame(s) :
    res = -1

    if len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "erase" :
      #print(s[0:len(s)-5])
      if len(s) - 5 > 0 :
        res = isdreame(s[0:len(s)-5])
      else :
          res = 1

    elif len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "dream" :
      #print(s[0:len(s)-5])
      if len(s) - 5 > 0 :
        res = isdreame(s[0:len(s)-5])
      else :
          res = 1

    elif len(s) - 6 >= 0 and s[len(s)-6:len(s)] == "eraser" :
      #print(s[0:len(s)-6])
      if len(s) - 6 > 0 :
        res = isdreame(s[0:len(s)-6])
      else :
          res = 1

    elif len(s) - 7 >= 0 and s[len(s)-7:len(s)] == "dreamer" :
      #print(s[0:len(s)-7])
      if len(s) - 7 > 0 :
        res = isdreame(s[0:len(s)-7])
      else :
          res = 1

    else :
        res = 0

    return res

s = input()
res = isdreame(s)

if res==1 :
    print("YES")
else :
    #print(res)
    print("NO")

Submission status: Memory Limit Exceeded

Solution code:
import sys
#input = sys.stdin.buffer.readline
sys.setrecursionlimit(100000)

def main():
    S = str(input())
    five = ["dream","erase"]
    def dream(s):
        if len(s) == 0:
            return True
        elif len(s) < 5:
            return False
        else:
            if s[:5] not in five:
                return False
            else:
                if s[:5] == "dream":
                    sf = s[5:]
                    if s[:7] == "dreamer":
                        se = s[7:]
                        return (dream(sf) or dream(se))
                    else:
                        return dream(sf)
                if s[:5] == "erase":
                    sf = s[5:]
                    if s[:6] == "eraser":
                        ss = s[6:]
                        return (dream(sf) or dream(ss))
                    else:
                        return dream(sf)
                
    if dream(S):
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

S = input()

T = ['dream', 'dreamer', 'erase', 'eraser']
lenT = [len(i) for i in T]

def dayDream(Sres_in):
    global isDream     #;print('dayDream: ', Sres_in)
    for i, d in enumerate(T):
        #print('d:', d)
        if Sres_in[:lenT[i]] == d:            
            Sres_out = Sres_in[lenT[i]:]
            if Sres_out =='':                
                isDream = True   #; print('YES')
                return 
            else:
                dayDream(Sres_out)
    #print('return', Sres_in)
    return
    
isDream = False
dayDream(S)
if isDream:
    print('YES')
else:
    print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(20000)

s=input()
sl=len(s)

def ok(st):    
    stl=len(st)
    if(sl<=stl):
        if(s==st):
            return True
        else:
            return False
    
    if(s[:stl]==st):
        del stl
        return ok(st+"dream") or ok(st+"dreamer") or ok(st+"erase") or ok(st+"eraser")
    
    return False

if(ok("")):
    print("YES")
else:
    print("NO")

Submission status: Memory Limit Exceeded

Solution code:
s = input()

kws = ["dream", "dreamer", "erase", "eraser"]

def func(s):
    if s == "":
        return True
    bool = False
    for kw in kws:
        if s.startswith(kw):
            bool = bool or func(s[len(kw):])
    return bool

result = func(s)

if result:
    print("YES")
else:
    print("NO")

Submission status: Memory Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

def dividable(S):
    return ((S[:5]=='dream'   and dividable(S[5:])) or
            (S[:7]=='dreamer' and dividable(S[7:])) or
            (S[:5]=='erase'   and dividable(S[5:])) or
            (S[:6]=='eraser'  and dividable(S[6:])) or
            (S==''))

print('YES' if dividable(input()) else 'NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(100000)

def f(S,L):
  if not L:
    return True
  if L >= 7:
    if S[-7:] == "dreamer":
      return f(S[:-7],L-7)
  if L >= 6:
    if S[-6:] == "eraser":
      return f(S[:-6],L-6)
  if L >= 5:
    if S[-5:] == "dream" or S[-5:] == "erase":
      return f(S[:-5],L-5)
  return False

s = input()
if f(s, len(s)):
  print("YES")
else:
  print("NO")

Submission status: Memory Limit Exceeded

Solution code:
def f(S,L):
  if not L:
    return True
  if L >= 7:
    if S[-7:] == "dreamer":
      return f(S[:-7],L-7)
  if L >= 6:
    if S[-6:] == "eraser":
      return f(S[:-6],L-6)
  if L >= 5:
    if S[-5:] == "dream" or S[-5:] == "erase":
      return f(S[:-5],L-5)
  return False

s = input()
if f(s, len(s)):
  print("YES")
else:
  print("NO")

Submission status: Memory Limit Exceeded

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

s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']
def dfs(t):
    if t == '':
        return True
    ans = False
    for word in words:
        if t[:len(word)] == word:
            ans = ans or dfs(t[len(word):])

    return ans

if dfs(s):
    print("YES")
else:
    print("NO")

Submission status: Memory Limit Exceeded

Solution code:

import bisect
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

s=input()

words = ["dream","dreamer","erase","eraser"]
def solve(s):
    if not s: return True
    for w in words:
        w_len = len(w)
        if len(s) < w_len: continue
        if w == s[0:w_len]:
            if solve(s[w_len:]):
                return True
    return False

print("YES" if solve(s) else "NO")

Submission status: Memory Limit Exceeded

Solution code:
s = input()

words = {'dream', 'dreamer', 'erase', 'eraser'}
words_with_blank = set.union({''}, words)

def is_daydream(s):
    if s in words_with_blank:
        return True
    elif s.startswith('dream')   and is_daydream(s[len('dream'):]):
        return True
    elif s.startswith('dreamer') and is_daydream(s[len('dreamer'):]):
        return True
    elif s.startswith('erase')   and is_daydream(s[len('erase'):]):
        return True
    elif s.startswith('eraser')  and is_daydream(s[len('eraser'):]):
        return True
    else:
        return False

if is_daydream(s):
    print('YES')
else:
    print('NO')

Submission status: Memory Limit Exceeded

Solution code:
x = input()
ans = "NO"
v = [x]
def f(s):
    global v
    if len(s)==0:
        global ans
        ans = "YES"
    else:
        if s[0:5] == "dream":
            v.append(s[5:])
        if s[0:7] == "dreamer":
            v.append(s[7:])
        if s[0:5] == "erase":
            v.append(s[5:])
        if s[0:6] == "eraser":
            v.append(s[6:])
while len(v)>0:
    f(v.pop())
print(ans)

Submission status: Memory Limit Exceeded

Solution code:
x = input()
ans = "NO"
def f(s):
    if len(s)==0:
        global ans
        ans = "YES"
    else:
        if s[0:5] == "dream":
            f(s[5:])
        if s[0:7] == "dreamer":
            f(s[7:])
        if s[0:5] == "erase":
            f(s[5:])
        if s[0:6] == "eraser":
            f(s[6:])
f(x)
print(ans)

Submission status: Memory Limit Exceeded

Solution code:
def check(S):
  ret = False
  if S[-5:] == 'dream':
    if len(S) == 5:
      ret = True
    else:
      ret = check(S[:-5])
  if S[-7:] == 'dreamer':
    if len(S) == 7:
      ret = True
    else:
      ret = check(S[:-7])
  if S[-5:] == 'erase':
    if len(S) == 5:
      ret = True
    else:
      ret = check(S[:-5])
  if S[-6:] == 'eraser':
    if len(S) == 6:
      ret = True
    else:
      ret = check(S[:-6])
  return ret

S = input()
ret = check(S)
if ret:
  print('YES')
else:
  print('NO')

Submission status: Memory Limit Exceeded

Solution code:
def judge(S):
	if S == '':
		return True
	if len(S) < 5:
		return False
	if len(S) >= 7:
		if S[-7:] == 'dreamer':
			return judge(S[:-7])
	if len(S) >= 6:
		if S[-6:] == 'eraser':
			return judge(S[:-6])
	if S[-5:] == 'dream' or S[-5:] == 'erase':
		return judge(S[:-5])
	return False

if judge(input()):
	print('YES')
else:
	print('NO')

Submission status: Memory Limit Exceeded

Solution code:
def judge(S):
	if len(S) == 0:
		return True
	if len(S) < 5:
		return False
	flag1 = False
	flag2 = False
	flag3 = False
	if len(S) >= 7:
		if S[-7:] == 'dreamer':
			flag1 = judge(S[:-7])
	if S[-6:] == 'eraser':
		flag2 = judge(S[:-6])
	if S[-5:] == 'dream' or 'erase':
		flag3 = judge(S[:-5])
	return flag1 or flag2 or flag3
if judge(input()):
	print('YES')
else:
	print('NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**6)

def rec(s):
  if s == '':
    return True
  else:
    if s[0:7] == 'dreamer'[::-1]:
      return rec(s[7:])
    elif s[0:5] == 'dream'[::-1]:
      return rec(s[5:])
    elif s[0:5] == 'erase'[::-1]:
      return rec(s[5:])
    elif s[0:6] == 'eraser'[::-1]:
      return rec(s[6:])
    return False
  
print('YES' if rec(input()[::-1]) else 'NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**6)

def rec(s):
  if s == '':
    return True
  else:
    res = False
    res = res or rec(s[7:]) if s[0:7] == 'dreamer'[::-1] else res
    res = res or rec(s[5:]) if s[0:5] == 'dream'[::-1] else res
    res = res or rec(s[5:]) if s[0:5] == 'erase'[::-1] else res
    res = res or rec(s[6:]) if s[0:6] == 'eraser'[::-1] else res
    return res
  
print('YES' if rec(input()[::-1]) else 'NO')

Submission status: Memory Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**6)

def rec(s):
  if s == '':
    return True
  else:
    res = False
    res = res or rec(s[7:]) if len(s) > 6 and s[0:7] == 'dreamer' else res
    res = res or rec(s[5:]) if len(s) > 4 and s[0:5] == 'dream' else res
    res = res or rec(s[5:]) if len(s) > 4 and s[0:5] == 'erase' else res
    res = res or rec(s[6:]) if len(s) > 5 and s[0:6] == 'eraser' else res
    return res
  
print('YES' if rec(input()) else 'NO')

Submission status: Memory Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

S = str(input())

def check(T):
    if len(S) == 0:
        return 1
    adds = ["dream","dreamer","erase","eraser"]
    q = copy.deepcopy(adds)
    while len(q) > 0:
        t = q.pop()
        if t == S:
            return 1
        for add in adds:
            if S[len(t):len(t+add)] == add:
                q.append(t+add)
    return 0

if check(""):
    print("YES")
else:
    print("NO")

Submission status: Memory Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

S = str(input())

def check(T):
    if T == S:
        return 1
    adds = ["dream","dreamer","erase","eraser"]
    ans = []
    for i,add in enumerate(adds):
        if S[len(T):len(T)+len(add)] == add:
            ans.append(T+add)
    i = 0
    for a in ans:
        if check(a) == None:
            pass
        else:
            i = 1
    if i == 1:
        return 1


# print(check(""))
if check(""):
    print("YES")
else:
    print("NO")