Problem p02954 (python)

Fixed submission:
S = input()
N = len(S)
ans=[0]*N


count=0
for i in range(N):
    if S[i]=="R":
        count+=1
    else:
        ans[i-1] += (count+1)//2
        ans[i] += count//2
        count=0

count=0
for i in range(1,N+1):
    if S[N-i]=="L":
        count+=1
    else:
        ans[N-i] += count//2
        ans[N-i+1] += (count+1)//2
        count=0

[print(x) for x in ans]

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans=[0]*N
S += "#"
#分割統治法
def RL(k):
    i=0
    count_R=0
    while S[min(k+i,N)]=="R":
        count_R +=1
        i += 1
        
    j=0
    count_L=0
    while S[min(k+i+j,N)]=="L" and S[min(k+i+j,N)]!="#":
        count_L += 1
        j+= 1
        
    
    ans[min(k+i-1,N-1)] += (count_R+1)//2+count_L//2
    ans[min(k+i,N-1)] += (count_R)//2+(count_L+1)//2

    if S[min(i+k+j,N)]!="#":
        RL(k+i+j)

RL(0)
[print(x) for x in ans]

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans=[0]*N
S += "#"
#分割統治法
def RL(k):
    i=0
    count_R=0
    while S[k+i]=="R" and S[k+i]!="#":
        count_R +=1
        i += 1
        
    j=0
    count_L=0
    while S[k+i+j]=="L" and S[k+i+j]!="#":
        count_L += 1
        j+= 1
        
    
    ans[k+i-1] += (count_R+1)//2+count_L//2
    ans[min(k+i,N-1)] += (count_R)//2+(count_L+1)//2

    if S[i+k+j]!="#":
        RL(k+i+j)

RL(0)
[print(x) for x in ans]

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans=[0]*N
S += "#"
#分割統治法
def RL(k):
    i=0
    count_R=0
    while S[k+i]=="R" and S[k+i]!="#":
        count_R +=1
        i += 1
        
    j=0
    count_L=0
    while S[k+i+j]=="L" and S[k+i+j]!="#":
        count_L += 1
        j+= 1
        
    
    ans[k+i-1] += (count_R+1)//2+count_L//2
    ans[k+i] += (count_R)//2+(count_L+1)//2

    if S[i+k+j]!="#":
        RL(k+i+j)

RL(0)
[print(x) for x in ans]

Buggy submission (verdict: Runtime Error):
count=0
for i in range(N):
    if S[i]=="R":
        count+=1
    else:
        ans[i-1] += (count+1)//2
        ans[i] += count//2
        count=0

count=0
for i in range(1,N):
    if S[N-i]=="L":
        count+=1
    else:
        ans[N-i] += count//2
        ans[N-i-1] += (count+1)//2
        count=0

[print(x) for x in ans]

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans=[0]*N
S += "#"
#分割統治法
def RL(k):
    i=0
    count_R=0
    while S[k+i]=="R":
        count_R +=1
        i += 1
    j=0
    count_L=0
    while S[k+i+j]=="L":
        count_L += 1
        j+= 1
        
    
    ans[k+i-1] += (count_R+1)//2+count_L//2
    ans[k+i] += (count_R)//2+(count_L+1)//2

    if S[i+k+j]!="#":
        RL(k+i+j)

RL(0)
[print(x) for x in ans]

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans=[0]*N
S += "#"
#分割統治法
def RL(k):
    i=0
    count_R=0
    while S[k+i]=="R":
        count_R +=1
        i += 1
    j=0
    count_L=0
    while S[k+i+j]=="L":
        count_L += 1
        j+= 1
        
    
    ans[k+i-1] += (count_R+1)//2+count_L//2
    ans[k+i] += (count_R)//2+(count_L+1)//2

    if S[i+k+j]!="#":
        RL(k+i+j)

RL(0)
[print(x) for x in ans]

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans=[0]*N
#分割統治法
def RL(k):
    i=0
    count_R=0
    while S[k+i]=="R":
        count_R +=1
        i += 1
    j=0
    count_L=0
    while S[k+i+j]=="L":
        count_L += 1
        if k+i+j==N-1:
            break
        j+= 1
        
    
    ans[k+i-1] += (count_R+1)//2+count_L//2
    ans[k+i] += (count_R)//2+(count_L+1)//2

    if k+i+j!=N-1:
        RL(k+i+j)

RL(0)
[print(x) for x in ans]

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans=[0]*N

def r_search(k):
    count=0
    i=0

    while S[k+i] == "R":
        count += 1
        i+=1

    ans[k+i] += count//2

    if count%2 == 0:
        ans[k+i-1] += count//2
    else:
        ans[k+i-1] += count//2+1
    
    if k+i!=N-1:
        l_search(k+i)
    else:
        ans[N-1]+=1


def l_search(k):
    count=0
    i=0

    while S[k+i] == "L":
        count += 1
        i+=1
        if k+i==N-1:
            count += 1
            break


    ans[k-1] += count//2
    if count%2 == 0:
        ans[k] += count//2
    else:
        ans[k] += count//2+1

    if k+i!=N-1:
        r_search(k+i)

r_search(0)

[print(x) for x in ans]