Problem: At an arcade, Takahashi is playing a game called _RPS Battle_ , which is played as follows:    * The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)   * Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):     * R points for winning with Rock;     * S points for winning with Scissors;     * P points for winning with Paper.   * However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)  Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.  The information Takahashi obtained is given as a string T. If the i-th character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.  What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

Submission attempts (in order):
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
data=[[0 for i in range(n//k)] for j in range(n//(n//k))]
ans=0
for i in range(0,n//(n//k)):
    for j in range(0,n//k):
        data[i][j]=t[i+(k*j)]

rz=0
sz=1
pz=2
for j in range(0,n//(n//k)):
    dp=[[0 for x in range(3)] for y in range(n//k)]
    if data[j][0]=='r':
        dp[0][rz]=0
        dp[0][sz]=0
        dp[0][pz]=p
    elif data[j][0]=='s':
        dp[0][rz]=r
        dp[0][sz]=0
        dp[0][pz]=0
    else :
        dp[0][rz]=0
        dp[0][sz]=s
        dp[0][pz]=0

    for i in range(1,n//k):
        if data[j][i]=='r':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+p+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='s':
            dp[i][rz]=dp[i][rz]+r+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        else :
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+s+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
    ans+=max(dp[-1][rz],dp[-1][sz],dp[-1][pz])
print(ans)

n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
if  n%k!=0:
    leng=n//k+1
else:
    leng=n//k
data=[[0 for i in range(leng)] for j in range(k)]
ans=0
for i in range(0,k):
    for j in range(0,leng):
        if i+(k*j)<n:
            data[i][j]=t[i+(k*j)]
rz=0
sz=1
pz=2
for j in range(0,k):
    dp=[[0 for x in range(3)] for y in range(leng)]
    if data[j][0]=='r':
        dp[0][rz]=0
        dp[0][sz]=0
        dp[0][pz]=p
    elif data[j][0]=='s':
        dp[0][rz]=r
        dp[0][sz]=0
        dp[0][pz]=0
    elif data[j][0]=='p':
        dp[0][rz]=0
        dp[0][sz]=s
        dp[0][pz]=0

    for i in range(1,leng):
        if data[j][i]=='r':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+p+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='s':
            dp[i][rz]=dp[i][rz]+r+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='p':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+s+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        else:
            dp[i][rz]=dp[i-1][rz]
            dp[i][sz]=dp[i-1][sz]
            dp[i][pz]=dp[i-1][pz]
    ans+=max(dp[-1][rz],dp[-1][sz],dp[-1][pz])
print(ans)

Verdicts: Wrong Answer

Accepted