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: Time Limit Exceeded

Solution code:
from collections import deque

S = input()

cands = ["dream", "dreamer", "erase", "eraser"]
searched = {}

queue = deque([""])
find_flag = 0
while len(queue) != 0:
    s = queue.popleft()
#     print(s)
    searched[s] = 1
    if s == S:
        find_flag = 1
        break
        
    s_ = cands[0]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)

    s_ = cands[1]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)
        
    s_ = cands[2]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)
        
    s_ = cands[3]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

S = input()

cands = ["dream", "dreamer", "erase", "eraser"]
searched = {}

queue = deque([""])
find_flag = 0
while len(queue) != 0:
    s = queue.pop()
#     print(s)
    searched[s] = 1
    if s == S:
        find_flag = 1
        break
        
    s_ = cands[0]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)

    s_ = cands[1]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)
        
    s_ = cands[2]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)
        
    s_ = cands[3]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

cands = ["dream", "dreamer", "erase", "eraser"]
searched = {}

queue = [""]
find_flag = 0
while len(queue) != 0:
    s = queue.pop(0)
    searched[s] = 1
    if s == S:
        find_flag = 1
        break
        
    s_ = cands[0]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)

    s_ = cands[1]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)
        
    s_ = cands[2]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)
        
    s_ = cands[3]
    if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
        queue.append(s+s_)

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

cands = ["dream", "dreamer", "erase", "eraser"]
searched = {}

queue = [""]
find_flag = 0
while len(queue) != 0:
    s = queue.pop(0)
    if s == S:
        find_flag = 1
        break
        
    for s_ in cands:
        if searched.get(s+s_):
            continue
        if (s+s_ == S[:len(s)+len(s_)]):
            searched[s+s_] = 1
            queue.append(s+s_)

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

cands = ["dream", "dreamer", "erase", "eraser"]
searched = {}

queue = [""]
find_flag = 0
while len(queue) != 0:
    s = queue.pop(0)
    if s == S:
        find_flag = 1
        break
        
    for s_ in cands:
        if (s+s_ == S[:len(s)+len(s_)]) & (not searched.get(s+s_)):
            searched[s+s_] = 1
            queue.append(s+s_)

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
S_len=len(S)
Word=['eraser','erase','dreamer','dream']

while True:
    if len(S)<4:
        break
    else:
        for i in Word:
            S = S.replace(i,"")
        if len(S)==S_len: #一つも文字が含まれなかった時break
            break
           
if len(S)==0:
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
S=input()
Word=['eraser','erase','dreamer','dream']

while True:
    if len(S)<4:
        break
    else:
        for i in Word:
          S = S.replace(i,"")
           
if len(S)==0:
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
#後ろから見たら一意
import sys
i = l-1
try:
    while i>0:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dremer":
                i-=7
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
            else:
                print("NO")
                sys.exit()
    print("YES")
except:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
#後ろから見たら一意
i = l-1
try:
    while i>0:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dremer":
                i-=7
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
    print("YES")
except:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
import re


def main():
    S = input()
    lens = len(S)
    while len(S):
        S = re.sub("dreamer$", "", S)
        S = re.sub("eraser$", "", S)
        S = re.sub("dream$", "", S)
        S = re.sub("erase$", "", S)
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
while len(s) >= 4:
  s.replace("eraser", "")
  s.replace("erase", "")
  s.replace("dreamer", "")
  s.replace("dream", "")
  if len(s) == 0:
    print('YES')
    exit()
print('NO')

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(S: str):
    while len(S)>4:
        if S[:11]=="dreameraser":
            S=S[11:]
        elif S[:10] == "dreamerase":
            S= S[10:]
        elif S[:6]=="eraser":
            S= S[6:]
        elif S[:5] == "erase" or S[:5]== "dream":
            S=S[5:]
        elif S[:7] == "dreamer":
            S=S[7:]
        else:
            print(NO)
        
    
    if len(S) == 0:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(S: str):
    while len(S)>4:
        if S[:6] == "eraser":
            S= S[6:]
        elif S[:5] == "erase" or S[:5]== "dream":
            S=S[5:]
        elif S[:7] == "dreamer":
            S=S[7:]
        else:
            print(NO)
        
    
    if len(S) == 0:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
S = str(input())

S_inv = S[::-1]

while(1):
    if S_inv=="":
        print("YES")
        sys.exit()
    
    elif len(S_inv)<=4:
        print("NO")
        sys.exit()
    
    elif len(S_inv)==5 and S_inv=="maerd":
        print("YES")
        sys.exit()
    
    elif len(S_inv)==5 and S_inv=="esare":
        print("YES")
        sys.exit()
    
    elif len(S_inv)==5 and (S_inv!="maerd" or S_inv!="esare"):
        print("NO")
        sys.exit()
        
    elif len(S_inv)==6 and S_inv!="resare":
        print("NO")
        sys.exit()
        
    elif len(S_inv)==7 and S_inv!="remaerd":
        print("NO")
        sys.exit()
        
    elif S_inv[:5] == "maerd":
        S_inv = S_inv[5:]
    
    elif S_inv[:5] == "esare":
        S_inv = S_inv[5:]
        
    elif S_inv[:6] == "resare":
        S_inv = S_inv[6:]
        
    elif S_inv[:7] == "remaerd":
        S_inv = S_inv[7:]

Submission status: Time Limit Exceeded

Solution code:
s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
  if s[:5]==p[0]:s=s.replace(p[0],"",1)
  elif s[:5]==p[3]:s=s.replace(p[3],"",1)
  elif s[:7]==p[1]:s=s.replace(p[1],"",1)
  elif s[:6]==p[2]:s=s.replace(p[2],"",1)
  else:
    if s=="":print("YES");break
    else:print("NO");break

Submission status: Time Limit Exceeded

Solution code:
s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
  if s[:5]==p[0]:s.replace(p[0],"",1)
  elif s[:5]==p[3]:s.replace(p[3],"",1)
  elif s[:7]==p[1]:s.replace(p[1],"",1)
  elif s[:6]==p[2]:s.replace(p[2],"",1)
  else:
    if s=="":print("YES");break
    else:print("NO");break

Submission status: Time Limit Exceeded

Solution code:
S = input()
divide = ["dream", "dreamer", "erase", "eraser"]
S = S[::-1]
divide = [divide[i][::-1] for i in range(4)]

while len(S) > 0:
    for i in range(4):
        if S[:len(divide[i])] == divide[i]:
            flag = "YES"
            S = S[len(divide[i]):]
            break
        else:
            flag = "NO"

print(flag)

Submission status: Time Limit Exceeded

Solution code:
s = input()

s_work = s
s_stack = []
while len(s_work) > 0:
    if s_work.startswith("dream"):
        s_stack.append("dream")
        s_work = s_work[len("dream"):]
    elif s_work.startswith("erase"):
        s_stack.append("erase")
        s_work = s_work[len("erase"):]
    else:
        if len(s_stack) == 0 or s_stack[-1].endswith("er"):
            print("NO")
            exit()
        s_work = s_stack.pop() + s_work
        if s_work.startswith("dreamer"):
            s_stack.append("dreamer")
            s_work = s_work[len("dreamer"):]
        elif s_work.startswith("eraser"):
            s_stack.append("eraser")
            s_work = s_work[len("eraser"):]
        else:
            print("NO")

print("YES")

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

s = ns()[::-1]
ans = "YES"

while len(s) > 1:
    if s[:5] == "maerd":
        s = s[5:]
    elif s[:7] == "remaerd":
        s = s[7:]
    elif s[:5] == "esare":
        s = s[5:]
    elif s[:6] == "resare":
        s = s[6:]
    else:
        ans = "NO"

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        dp = [False] * (len(S) + 1)

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

        dp[0] = True
        for i in range(len(S)):
            if not dp[i]:
                continue
            for word in words:
                if S[i:].startswith(word):
                    dp[i + len(word)] = True

        print('YES' if dp[len(S)] else 'NO')


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
re_list = [r'dream$', r'dreamer$', r'erase$', r'eraser$']
while True:
  if s == '':
    print('YES')
    break
  for regex in re_list:
    m = re.sub(regex, '', s)
    if m != s:
      s = m
      break
  else:
    print('NO')
    break
  continue

Submission status: Time Limit Exceeded

Solution code:
from re import sub

dest = input().rstrip("\n")

suffixes = ["dream$", "dreamer$", "erase$", "eraser$"]

while True:
    len_before = len(dest)
    for suffix in suffixes:
        dest = sub(suffix, "", dest)
    if len(dest) == len_before:
        break

print("YES" if not dest else "NO")

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
T = "dummy"
words = ["maerd", "remaerd", "esare", "resare"]
while True:
    for i in range(len(words)):
        if S[0:len(words[i])] == words[i]:
            S = S.replace(S[0:len(words[i])], "", 1)
    if S == "":
        print("YES")
        break
    elif T == S:
        print("NO")
        break
    else:
        T = S

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

checker = True
while checker == True:
    if S == "":
        checker = False
    elif S[-1] == "r":
        if S[-7:] == "dreamer":
            if len(S) >= 7:
                S = S[:-7]
            else:
                checker = False
        elif S[-6:] == "eraser":
            if len(S) >= 6:
                S = S[:-6]
            else:
                checker = False
        else:
            continue
    elif S[-1] == "e":
        if S[-5:] == "erase":
            if len(S) >= 5:
                S = S[:-5]
            else:
                checker = False
    elif S[-1] == "m":
        if S[-5:] == "dream":
            if len(S) >= 5:
                S = S[:-5]
            else:
                checker = False
    else:
        checker = False

        
if S == "":
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

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

while s != '':
    tmp = s
    s = re.sub(r'dream$', '', s)
    s = re.sub(r'dreamer$', '', s)
    s = re.sub(r'erase$', '', s)
    s = re.sub(r'eraser$', '', s)
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Submission status: Time Limit Exceeded

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

while s != '':
    tmp = s
    for word in words:
        s = re.sub(r'dream$', '', s)
        s = re.sub(r'dreamer$', '', s)
        s = re.sub(r'erase$', '', s)
        s = re.sub(r'eraser$', '', s)
    if s == '':
        print('YES')
    if tmp == s:
        print('NO')
        break

Submission status: Time Limit Exceeded

Solution code:
S = input()

while len(S) > 0:
  if "dreameraser" in S:
    S = S.replace("dreameraser","")
  elif "dreamer" in S:
    S = S.replace("dreamer","")
  elif "dream" in S:
    S = S.replace("dream","")
  elif "eraseer" in S:
    S = S.replace("eraser","")
  elif "erase" in S:
    S = S.replace("erase","")
  else:
    break
    
if len(S) == 0:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
S = input()

while len(S) > 0:
  if "dreameraser" in S:
    S = S.replace("dreameraser","")
  elif "dream" in S:
    S = S.replace("dreamer","")
  elif "dreamer" in S:
    S = S.replace("dream","")
  elif "erase" in S:
    S = S.replace("eraser","")
  elif "eraser" in S:
    S = S.replace("erase","")
  else:
    break
    
if len(S) == 0:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
st = input()

sample = ['dream', 'dreamer', 'erase', 'eraser']
sample_edit = ['dream', 'eraser','erase', 'er']
sample_er = ['er']
sample_dr = ['dream']
sample_ase = ['ase', 'aser']

ret = 'NO'
reg_len = 0
fd_word = ''
dream_flg = False
end_flg = False

while( len(st) != 0 ):
  if reg_len == len(st):
    break
  
  reg_len = len(st)
  for i in range(len(sample_edit)):
    fd = st.startswith(sample_edit[i])
    
    if fd > 0:
      
      #print(st,i,dream_flg)
      st = ''.join(st[len(sample_edit[i]):len(st)])
        
      if sample_edit[i] == 'dream':
        dream_flg = True
      elif sample_edit[i] == 'er':
        if dream_flg == False:
          end_flg = True
        else:
          dream_flg = False
      
      break
    
        
  if end_flg == True:
    break
    
  if len(st) == 0:
    ret = 'YES'
    
  #print(st)
  #print(len(st))

print( ret )

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
D = [s[::-1] for s in ["dream", "dreamer", "erase", "eraser"]]

i = 0
flg = True
while i < len(S):
  for d in D:
    if S[i:i+len(d)] == d:
      i += len(d)
      break
    flg = False
    break

if flg:
  print('YES')
else:
  print('NO')

Submission status: Time Limit Exceeded

Solution code:
S = input()
T = ""
count = 0
while 1:
    count = 0

    T = "dreamer" + T
    if S[-len(T)::] != T:
        count += 1
        t = list(T)
        for i in range(7):
            t.pop(0)
        T = ''.join(t)
    else:
        continue

    T = "dream" + T
    if S[-len(T)::] != T:
        count += 1
        t = list(T)
        for i in range(5):
            t.pop(0)
        T = ''.join(t)
    else:
        continue

    T = "eraser" + T
    if S[-len(T)::] != T:
        count += 1
        t = list(T)
        for i in range(6):
            t.pop(0)
        T = ''.join(t)
    else:
        continue

    T = "erase" + T
    if S[-len(T)::] != T:
        count += 1
        t = list(T)
        for i in range(5):
            t.pop(0)
        T = ''.join(t)
    else:
        continue

    if count == 4:
        break

if T == S:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
S = input()
CANDIDATES = ['dream', 'dreamer', 'erase', 'eraser']

def word_in_str(word, str, num):
    word_list = list(word)
    str_list = list(str)
    for i in range(len(word_list)):
        if i + num >= len(str) or word_list[i] != str_list[i + num]:
            return False
    return True

def reccurent_search(candidates, str, num):
    for c in candidates:
        if word_in_str(c, str, num):
            if num + len(c) == len(str):
                print('YES')
                exit()
            reccurent_search(candidates, str, num + len(c))

reccurent_search(CANDIDATES, S, 0)
print('NO')

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
t = ''
here = 0
er = 0
r = 0
flag = 1
while here < n:
  if s[here] == 'e' and here + 2 < n:
    if s[here:here+3] == 'era':
      t += 'erase'
      here += 5
      er = 0
      r = 1
    elif s[here] == 'e' and er == 1:
      t += 'er'
      here += 2
      er = 0
      r = 0
  elif s[here] == 'e' and er == 1:
    t += 'er'
    here += 2
    er = 0
    r = 0
  elif s[here] == 'd':
    t += 'dream'
    here += 5
    er = 1
    r = 0
  elif s[here] == 'r' and r == 1:
    t += 'r'
    here += 1
    er = 0
    r = 0
  else:
    flag = 0
    break
if s == t and flag == 1:
  print('YES')
else:
  print('NO')

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]
cpos = 0
while True:
  for b in words:
    pos = s.find(b)
    if pos == cpos:
      cpos += len(b)
      break
  if cpos == len(s):
    print('YES')
    break
  elif pos == -1:
    print('NO')
    break

Submission status: Time Limit Exceeded

Solution code:
import re
if __name__ == '__main__':
    S = str(input())
while True:
    S_new = re.sub(r'eraser$|erase$|dreamer$|dream$', '', S)
    if S_new == S:
        print('NO')
        break
    elif S_new == '':
        print('YES')
        break
    S = S_new

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = list(S)
S.reverse()
T = []
n = len(S)
for i in range(n):
  T.append(S[i])
  mojiretu = ''.join(T)
  if mojiretu == "maerd" or mojiretu == "remaerd" or mojiretu == "esare" or mojiretu == "resare":
    T =[]
 
N = len(T)
if N == 0:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = list(S)
S.reverse()
T = []
n = len(S)
for i in range(n):
  T.append(S[i])
  mojiretu = ''.join(T)
  if mojiretu == "maerd" or mojiretu == "remaerd" or mojiretu == "esare" or mojiretu == "resare":
    T =[]

N = len(T)
if N == 0:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = s[::-1]

p1 = 'dream'
p2 = 'dreamer'
p3 = 'erase'
p4 = 'eraser'

e_flag = True

while True :
  if s[:5] == p1[::-1] :
    s = list(s)
    del s[:5]
    s = ''.join(s)
    e_flag = False
  elif s[:7] == p2[::-1] :
    s = list(s)
    del s[:7]
    s = ''.join(s)
    e_flag = False
  elif s[:5] == p3[::-1] :
    s = list(s)
    del s[:5]
    s = ''.join(s)
    e_flag = False
  elif s[:6] == p4[::-1] :
    s = list(s)
    del s[:6]
    s = ''.join(s)
    e_flag = False

  if e_flag :
    print('NO')
    break
  
  if s == '' :
    print('YES')
    break

  e_flag = True

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_list = list(S)

while len(S_list) >= 5 :
    a = len(S_list)
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if a >= 6 :
            if S_list[5] == 'r' :
                del S_list[0:6]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if a >= 8 :
            if S_list[5:8] == ['e', 'r', 'a'] :
                del S_list[0:5]
        elif a >= 7 :
            if S_list[5:7] == ['e', 'r'] :
                del S_list[0:7]
        else :
            del S_list[0:5]
    else:
        print('NO')
        break


if len(S_list) == 0:
    print('YES')
elif 0<len(S_list)<5:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_list = list(S)

while len(S_list) >= 5 :
    if S_list[0:5] == ['e', 'r', 'a', 's', 'e']:
        if len(S_list) >= 6 :
            if S_list[5] == 'r' :
                del S_list[0:6]
        else:
            del S_list[0:5]
    elif S_list[0:5] == ['d', 'r', 'e', 'a', 'm']:
        if len(S_list) >= 8 :
            if S_list[5:8] == ['e', 'r', 'a'] :
                del S_list[0:5]
        elif len(S_list) >= 7 :
            if S_list[5:7] == ['e', 'r'] :
                del S_list[0:7]
        else :
            del S_list[0:5]
    else:
        print('NO')
        break


if len(S_list) == 0:
    print('YES')
elif 0<len(S_list)<5:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = S[::-1]
t = ['maerd','remaerd','esare','resare']
i = 0
frag = 0
while i <= len(S)-1 and frag == 0:
  k = 0
  for j in range(4):
    d = t[j]
    if S[i:len(d)+i] == d:
      break
      i = i + len(d)
    else:
      k = k + 1
      if k == 4:
        frag = 1
        print('NO')
if i == len(S):
  print('YES')

Submission status: Time Limit Exceeded

Solution code:
import re  # 正規表現, findall('正規表現', 文字列), search('正規表現', 文字列)
import sys # プログラム終了：sys.exit()
# sys.setrecursionlimit(10**6) # 再帰呼び出しの上限を上げる

def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))
# 文字列のまま受け取りたいときはinput()

def main():
    S = input()

    while 1:
        if S == '':
            print('YES')
            sys.exit()
        elif re.search('dreamer$', S):
            S = S[:-7]
            # print('a', S)
        elif re.search('eraser$', S):
            S = S[:-6]
            # print('b', S)
        elif re.search('dream$', S):
            S = S[:-5]
            # print('c', S)
        elif re.search('erase$', S):
            S = S[:-5]
            # print('d', S)
        else:
            print('NO')
            sys.exit()

    print('YES')

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def word_break(s, words):
    ok = [True]
    for i in range(1, len(s)+1):
        ok += any(ok[j] and s[j:i] in words for j in range(i)),
    return ok[-1]


s = input()
words = ["eraser", "erase", "dreamer", "dream"]
print("YES" if word_break(s, words) else "NO")

Submission status: Time Limit Exceeded

Solution code:
from re import search


# f = open("./16/input_c2_2.txt")


# def input():
#     return f.readline().rstrip()


def main():
    S = input()

    while True:
        result_1 = search('dreamer$', S)
        result_2 = search('eraser$', S)
        result_3 = search('erase$', S)
        result_4 = search('dream$', S)

        if result_1:
            S = S[:result_1.start()]
        elif result_2:
            S = S[:result_2.start()]
        elif result_3:
            S = S[:result_3.start()]
        elif result_4:
            S = S[:result_4.start()]
        else:
            print("NO")
            break

        if len(S) == 0:
            print("YES")
            break


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
keys = ["dream", "dreamer", "erase", "eraser"]
keys_ = [i[::-1] for i in keys]
i = 0
t = ''

while(i < len(s)):
  for key in keys_:
    if s[i:].startswith(key):
      t += key
      i += len(key)
    if t == s:
      print('YES')
      exit()
    else:
      continue
else:
  print('NO')

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
keys = ["dream", "dreamer", "erase", "eraser"]
keys_ = [i[::-1] for i in keys]
i = 0
t = ''

while(i < len(s)):
  for key in keys_:
    if s[i:].startswith(key):
      t += key
      i += len(key)
    if t == s:
      print('YES')
      exit()
    else:
      continue
else:
  print(t)
  print('NO')

Submission status: Time Limit Exceeded

Solution code:
import copy
S=list(input())
while len(S)>0:
    if S[0:7]==['d','r','e','a','m','e','r'] and (len(S)==7 or S[7]!='a'):
        for _ in range(7):
            S.pop(0)
    elif S[0:5]==['d','r','e','a','m']:
        for _ in range(5):
            S.pop(0)
    elif S[0:6]==['e','r','a','s','e','r']:
        for _ in range(6):
            S.pop(0)
    elif S[0:5]==['e','r','a','s','e']:
        for _ in range(5):
            S.pop(0)
    else:
        print('NO')
        exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
s1=reversed(s)
l=["dream","dreamer","erase","eraser"]
s2=[]
for item in s1:
  s2.insert(0,item)
  str=''.join(s2)
  if str in l:
    s2=[]
if len(s2)==0:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
import queue
divide=["dream","dreamer","erase","eraser"]
S=input()
q=queue.Queue()
q.put(0)
can=False
while not q.empty():
        t=q.get()
        q.get()
        if t==len(S): 
                can=True
                break
        for s in divide:
                if S[t:t+len(S)]==s:
                        q.put(t+len(s))
print("YES") if can else print("NO")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

S = list(reversed(list(input().strip())))
P = [list(reversed(v)) for v in ["dream", "dreamer", "erase", "eraser"]]

sys.setrecursionlimit(10000)
def dfs(n):
    if len(S[n:]) == 0:
        return True
    
    for v in P:
        if S[n:n+len(v)] == v:
            if dfs(n + len(v)):
                return True
    
    return False

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

S = list(input().strip())
P = [list(v) for v in ["dream", "dreamer", "erase", "eraser"]]

sys.setrecursionlimit(10000)
def dfs(n):
    if len(S[n:]) == 0:
        return True
    
    for v in P:
        if S[n:n+len(v)] == v:
            if dfs(n + len(v)):
                return True
    
    return False

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)
a=['dream','dreamer','erase','eraser']
a=list(map(lambda x:x[::-1],a))
def check(c):
    if c=='':
        return True
    rt=False
    size=len(c)
    for i in a:
        if size>=len(i) and c[-len(i):]==i:
            rt=check(c[:-len(i)]) or rt
    return rt

print('YES' if check(input()[::-1]) else 'NO')

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
while len(S) > 0:
    if ''.join(S[-5:]) == 'dream' or ''.join(S[-5:]) == 'erase':
        S = S[:-5]
    elif ''.join(S[-6:]) == 'eraser':
        S = S[:-6]
    elif ''.join(S[-7:]) == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        quit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
while len(S) > 0:
    if ''.join(S[-5:]) == 'dream' or ''.join(S[-5:]) == 'erase':
        S = S[:-5]
    elif ''.join(S[-6:]) == 'eraser':
        S = S[:-6]
    elif ''.join(S[-7:]) == 'dreamer':
        S = S[-7:]
    else:
        print('NO')
        quit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
import re

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

def del_r(s):
    _s = s
    success = False
    for de in de_list:
        search = de+'$'
        s = re.sub(search, '', s)
        if s != _s:
            success = True
    return success, s

roop_flg = True
while(roop_flg):
    roop_flg, S = del_r(S)

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

Submission status: Time Limit Exceeded

Solution code:
import re

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

def del_r(s):
    success = False
    for de in de_list:
        search = de+'$'
        if re.search(search, S) is not None:
            s = re.sub(search, '', s)
            success = True
    return success, s

roop_flg = True
while(roop_flg):
    roop_flg, S = del_r(S)

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

Submission status: Time Limit Exceeded

Solution code:
#英小文字からなる文字列 S が与えられます。T が空文字列である状態から始めて、以下の操作を好きな回数繰り返すことで S=T とすることができるか判定してください。
#T の末尾に "dream", "dreamer", "erase", "eraser" のいずれかを追加する。


s=input()
s1="dream"
s2="dreamer"
s3="erase"
s4="eraser"
l=len(s)

rest="NO"

while l>4:
	if s[-5:]==s1 or s[-5:]==s3:
		s=s[0:-5]
		l=l-5
	elif s[-6:]==s4:
		s=s[0:-6]
		l=l-6
	elif s[-7:]==s2:
		l=l-7
		s=s[0:-7]

if l==0:
	rest="YES"

print(rest)

Submission status: Time Limit Exceeded

Solution code:
import sys
S = input()

length = len(S)
i = length

while i > 0:
    if S[i-5:i] == 'dream':
        i -= 5
    elif S[i-7:i] == 'dreamer':
        i -= 7
    elif S[i-5:i] == 'erase':
        i -= 5
    elif S[i-6:i] == 'eraser':
        i -= 6
    else:
        print('NO')
    
print('YES')

Submission status: Time Limit Exceeded

Solution code:
#
# abc049 c
#
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']

flag = 0
while len(s) > 0:
    for w in words:
        if s[-1 * len(w):] == w:
            s = s.replace(w, "").rstrip()
            flag = 1
            break
    if flag == 0:
        print("NO")
        exit()

print("YES")