Problem:


Score : 400 points

Problem Statement

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?

Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

if both players play the same hand, it is a draw.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

1 \leq R,S,P \leq 10^4

N,K,R,S, and P are all integers.

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.
We cannot earn more points, so the answer is 27.

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996



Sample input:
5 2
8 7 6
rsrpr


Sample output:
27

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())

T = list(input())

for i in range(n):
    l = T[i]
    if(l == "r"):
        T[i] = p
    if(l == "s"):
        T[i] = r
    if(l == "p"):
        T[i] = s

sm = 0
#print(T)
for i in range(n):
    sm += T[i]
#print(sm)

for i in range(k,n):
    if(T[i-k]==T[i]):
        sm -= T[i]
        T[i] = 0

print(sm)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k = map(int,input().split())
r,s,p = map(int,input().split())
point_dict = {"r":p,"s":r, "p":s}
t = input()
# ゲームの問題
# ジャンケンをNかいする
# Kかい前の手と同じ手を出すことはできない
# 事前に相手が出す手がわかっている時の得点の最大化
# for i in range(k): に対してi+k*j 番目での手を前からgreedyにう考える
# bit を立ててk個前と同じ手だった時に勝てる手を出していいかを管理
ans = 0
for i in range(k):
    bit = 1 # 勝てる手を出していい
    j =0
    ans += point_dict[t[i+k*j]]
    j += 1
    while i+k*j <= n-1:
        if t[i+k*j] != t[i+k*j-k]:
            ans += point_dict[t[i+k*j]]
        elif (t[i+k*j] == t[i+k*j-k] and bit == 0):
            ans += point_dict[t[i+k*j]]
            #print(t[i+k*j])
            bit = 1
        else:
            bit = 0
        j += 1
        #print(ans,i,j)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
table = { "r": p, "s": r, "p": s }

score = [0] * n
for i in range(n):
    if i-k < 0:
        score[i] = table[t[i]]
        continue
    if score[i-k] != table[t[i]]:
        score[i] = table[t[i]]

print(sum(score))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
table = { "r": p, "s": r, "p": s }

score = [0] * n
for i in range(n):
    if i-k < 0:
        score[i] = table[t[i]]
        continue
    if score[i-k] != 0 and score[i-k] == table[t[i]]:
        score[i] = 0
    else:
        score[i] = table[t[i]]

print(sum(score))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
score = [0] * n
table = { "r": p, "s": r, "p": s }
for key, v in enumerate(t):
    if key-k < 0:
        score[key] = table[v]
        continue
    if score[key-k] != 0 and score[key-k] == table[v]:
        score[key] = 0
    else:
        score[key] = table[v]

print(sum(score))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
cnt=0
hand=[]
for i in range(len(t)):
    if i<=k-1:
        if t[i]=="r":
            hand.append("p")
            cnt+=p
        elif t[i]=="s":
            hand.append("r")
            cnt+=r
        elif t[i]=="p":
            hand.append("s")
            cnt+=s
    elif k<=i:
        if t[i]=="r":
            if hand[i-k]!="p":
                hand.append("p")
                cnt+=p
            else:
                hand.append("r")
        elif t[i]=="s":
            if hand[i-k]!="r":
                hand.append("r")
                cnt+=r
            else:
                hand.append("s")

        elif t[i]=="p":
            if hand[i-k]!="s":
                hand.append("s")
                cnt+=s
            else:
                hand.append("p")
print(cnt)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())

win = {"r":"p","s":"r","p":"s"}
point = {"r":r,"s":s,"p":p}

ans = []
sum = 0

for i in range(k):
    ans.append(win[t[i]])
    sum+=point[win[t[i]]]

for i in range(k,n):
    if win[t[i]] == ans[i - k]:
        ans.append(t[i])
    else:
        ans.append(win[t[i]])
        sum+=point[win[t[i]]]
print(sum)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t_list = input()
pre_list = []
towin = {"r": "p", "s": "r", "p": "s"}
topoint = {"r": r, "s": s, "p": p}
pre = {}
if s >= p:
    pre["r"] = "s"
else:
    pre["r"] = "p"
if s >= r:
    pre["s"] = "r"
else:
    pre["s"] = "p"
if r >= s:
    pre["p"] = "r"
else:
    pre["p"] = "s"
ans = 0
for i in range(n):
    win_hand = towin[t_list[i]]
    if i <= k:
       ans += topoint[win_hand]
       pre_list.append(win_hand)
    else:
        if win_hand == pre_list[i - k]:
            if i < n - k:
                hand = pre[t_list[i + k]]
                pre_list.append(hand)
        else:
            ans += topoint[win_hand]
            pre_list.append(win_hand)
print(ans)

Submission status: Wrong Answer

Solution code:
game_num, k = map(int, input().split())
r_score, s_score, p_score = map(int, input().split())
game = input()
score = 0
waste_r, waste_s, waste_p = [], [], []
count_waste_r = count_waste_s = count_waste_p = 0

for i in range(game_num):
    if i < k:
        pass
    elif game[i] == 'r' and game[i - k] == 'r' and not (i - k) in waste_r:
        count_waste_r += 1
        if len(waste_r) > 2 * k:
            waste_r.pop()
        waste_r.append(i)
    elif game[i] == 's' and game[i - k] == 's' and not (i - k) in waste_s:
        count_waste_s += 1
        if len(waste_s) > 2 * k:
            waste_s.pop()
        waste_s.append(i)
    elif game[i] == 'p' and game[i - k] == 'p' and not (i - k) in waste_p:
        count_waste_p += 1
        if len(waste_p) > 2 * k:
            waste_p.pop()
        waste_p.append(i)

r_count, s_count, p_count = map(lambda x: game.count(x), ['r', 's', 'p'])

score += r_count * p_score + s_count * r_score + p_count * s_score
score -= count_waste_r * p_score + count_waste_s * r_score + count_waste_p * s_score
print(score)

Submission status: Wrong Answer

Solution code:
game_num, k = map(int, input().split())
r_score, s_score, p_score = map(int, input().split())
game = input()
score = 0
waste_r, waste_s, waste_p = [], [], []
count_waste_r = count_waste_s = count_waste_p = 0

for i in range(game_num):
    if i < k:
        pass
    elif game[i] == 'r' and game[i - k] == 'r' and not (i - k) in waste_r:
        waste_r.append(i)
        count_waste_r += 1
        if len(waste_r) > k + 1:
            waste_r.pop()
    elif game[i] == 's' and game[i - k] == 's' and not (i - k) in waste_s:
        waste_s.append(i)
        count_waste_s += 1
        if len(waste_s) > k + 1:
            waste_s.pop()
    elif game[i] == 'p' and game[i - k] == 'p' and not (i - k) in waste_p:
        waste_p.append(i)
        count_waste_p += 1
        if len(waste_p) > k + 1:
            waste_p.pop()

r_count, s_count, p_count = map(lambda x: game.count(x), ['r', 's', 'p'])

score += r_count * p_score + s_count * r_score + p_count * s_score
score -= count_waste_r * p_score + count_waste_s * r_score + count_waste_p * s_score
print(score)

Submission status: Wrong Answer

Solution code:
game_num, k = map(int, input().split())
r_score, s_score, p_score = map(int, input().split())
game = input()
score = 0
waste_r, waste_s, waste_p = [], [], []
count_waste_r = count_waste_s = count_waste_p = 0

for i in range(game_num):
    if i < k:
        pass
    elif game[i] == 'r' and game[i - k] == 'r' and not (i - k) in waste_r:
        waste_r.append(i)
        count_waste_r += 1
        if len(waste_r) > k:
            waste_r.pop()
    elif game[i] == 's' and game[i - k] == 's' and not (i - k) in waste_s:
        waste_s.append(i)
        count_waste_s += 1
        if len(waste_s) > k:
            waste_s.pop()
    elif game[i] == 'p' and game[i - k] == 'p' and not (i - k) in waste_p:
        waste_p.append(i)
        count_waste_p += 1
        if len(waste_p) > k:
            waste_p.pop()

r_count, s_count, p_count = map(lambda x: game.count(x), ['r', 's', 'p'])

score += r_count * p_score + s_count * r_score + p_count * s_score
score -= count_waste_r * p_score + count_waste_s * r_score + count_waste_p * s_score
print(score)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
T=list(T)

score=0

for i in range(N):
    if i<(K-1) or T[i-K]!=T[i]:
        if T[i]=="r":
            score+=P
        elif T[i]=="p":
            score+=S
        else:
            score+=R
    else:
        if T[i]=="r":
            T[i]="a"
        elif T[i]=="p":
            T[i]="a"
        else:
            T[i]="a"

print(score)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
T=list(T)

score=0

for i in range(N):
    if i<(K-1) or T[i-K]!=T[i]:
        if T[i]=="r":
            score+=P
        elif T[i]=="p":
            score+=S
        else:
            score+=R
    else:
        if T[i]=="r":
            T[i]="s"
        elif T[i]=="p":
            T[i]="r"
        else:
            T[i]="p"

print(score)

Submission status: Wrong Answer

Solution code:
import math
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np

n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
# p = list(map(int, input().split()))
score = 0
rev = [False] * k
for i in range(k):
    if t[i] == 'r':
        score += p

    elif t[i] == 'p':
        score += s

    elif t[i] == 's':
        score += r

for i in range(k,n):

    if t[i] == t[i-k] and not rev[(i+1)%k] :
        rev[i % k] = True

    elif t[i] == t[i-k] and rev[(i+1)%k] :
        if t[i]=='r': score += p
        elif t[i] == 'p': score += s
        elif t[i] == 's': score += r

        rev[i % k] = False

    elif t[i] != t[i-k]:
        if t[i]=='r': score += p
        elif t[i] == 'p': score += s
        elif t[i] == 's': score += r

        rev[i % k] = True

print(score)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
x = ["" for _ in range(N)]
ans = 0
for i in range(N):
    if K <= i:
        if T[i] == "r":
            if x[i-K] == "p":
                x[i] = "r"
            else:
                ans += P
                x[i] = "p"
        elif T[i] == "s":
            if x[i-K] == "r":
                x[i] = "s"
            else:
                ans += R
                x[i] = "r"
        elif T[i] == "p":
            if x[i-K] == "s":
                x[i] = "p"
            else:
                ans += S
                x[i] = "s"
    else:
        if T[i] == "r":
            ans += P
            x[i] = "p"
        elif T[i] == "s":
            ans += R
            x[i] = "r"
        elif T[i] == "p":
            ans += S
            x[i] = "s"
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

data = {"r": P, "s": R, "p": S}
ans = 0

for i in range(K):
    score = data[T[i]]
    ans += score

    for j in range(i + K, N, K):
        if data[T[j]] == score:
            score = 0
        else:
            score = data[T[j]]
            ans += score

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

data = {"r": P, "s": R, "p": S}
ans = 0

for i in range(1, K + 1):
    score = data[T[N - i]]
    ans += score

    for j in range(i + K, N + 1, K):
        if data[T[N - j]] == score:
            score = 0
        else:
            score = data[T[N - j]]
            ans += score

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
R,S,P = map(int,input().split())
t = list(input())

L = [0]*n
for i in range(n):
    if i <=k-1:
        if t[i] == "r":
            L[i] = "p"
        elif t[i] == "s":
            L[i] = "r"
        elif t[i] == "p":
            L[i] = "s"
    elif i >k-1:
        if t[i] == t[i-k]:
            L[i] = "0"
        else:
            if t[i] == "r" and (L[i-k] != "0"):
                L[i] = "p"
            elif t[i] == "s" and (L[i-k] != "0"):
                L[i] = "r"
            elif t[i] == "p" and (L[i-k] != "0"):
                L[i] = "s"
            elif (L[i-k] == "0"):
                if t[i] == "r":
                    L[i] = "p"
                elif t[i] == "s":
                    L[i] = "r"
                elif t[i] == "p":
                    L[i] = "s"

ans = 0
for i in range(n):
    if L[i] == "p":
        ans +=P
    elif L[i] == "r":
        ans += R
    elif L[i] == "s":
        ans += S
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = str(input())
score = 0
lose = -1
def janken(hand):
    if hand == 'r':
        return(p)
    if hand == 's':
        return(r)
    if hand == 'p':
        return(s)

for i in range(n):
    if i <= k - 1:
        score += janken(T[i])
    else:
        if T[i] == T[i - k]:
            if lose != i - k:
                lose = i
            else:
                score += janken(T[i])
        else:
            score += janken(T[i])
print(score)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = str(input())
score = 0
lose = -10
def janken(hand):
    if hand == 'r':
        return(p)
    if hand == 's':
        return(r)
    if hand == 'p':
        return(s)

for i in range(n):
    if i <= k - 1:
        score += janken(T[i])
    else:
        if T[i] == T[i - k]:
            if i - k != lose:
                lose = i
            else:
                score += janken(T[i])
        else:
            score += janken(T[i])
print(score)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = str(input())
score = 0
lose = -1
def janken(hand):
    if hand == 'r':
        return(p)
    if hand == 's':
        return(r)
    if hand == 'p':
        return(s)

for i in range(n):
    if i <= k - 1:
        score += janken(T[i])
    else:
        if T[i] == T[i - k]:
            if i - k != lose:
                lose = i
            else:
                score += janken(T[i])
        else:
            score += janken(T[i])
print(score)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = str(input())
score = 0
lose = 0
def janken(hand):
    if hand == 'r':
        return(p)
    if hand == 's':
        return(r)
    if hand == 'p':
        return(s)

for i in range(n):
    if i <= k - 1:
        score += janken(T[i])
    else:
        if T[i] == T[i - k]:
            if i - k != lose:
                lose = i
            else:
                score += janken(T[i])
        else:
            score += janken(T[i])
print(score)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
r,s,p = map(int, input().split())
T = input()
P = []
for i in range(n):
    if T[i] == 'r':
        P.append(p)
    elif T[i] == 's':
        P.append(r)
    elif T[i] == 'p':
        P.append(s)

for i in range(n-k):
    if P[i] == P[i+k]:
        P[i+k] = 0

print(sum(P))

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
r,s,p = map(int, input().split())
T = input()
P = []
for i in range(n):
    if T[i] == 'r':
        P.append(p)
    elif T[i] == 's':
        P.append(r)
    elif T[i] == 'p':
        P.append(s)
    else:
        print(4)

for i in range(n-k):
    if P[i] == P[i+k]:
        P[i+k] = 0

print(sum(P))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split()) #RSP グーチョキパー
T=list(input())

c=0

def jan(a):
    if a=="r":
        return P
    elif a=="s":
        return R
    elif a=="p":
        return S
    else:
        return 0

for i in range(1,N):
    if T[i]==T[i-1]:
        T[i]="o"

for i in range(1,K+1): #modK
    for j in range(N//K+1):
        if i+K*j>N:
            continue
        c+=jan(T[i+K*j-1])

print(c)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
score = 0

for i in range(len(t)):

    if i <= k:
        if t[i] == 'r':
            score += p
        elif t[i] == 's':
            score += r
        else:
            score += s
    else:
        if t[i] == 'r' and t[i - k] != t[i]:
            score += p
        elif t[i] == 's' and t[i - k] != t[i]:
            score += r
        else:
            if t[i] == 'p' and t[i - k] != t[i]:
                score += s

print(score)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()

def MaxScore(rsp, s):
    Score = 0
    t = list(s)
    t = t + ['t']
    for i in range(len(t)-1):
        if t[i] == t[i+1]:
            t[i+1] = 'x' + t[i+1]
    for i in range(len(t)):
        if t[i] == 'r':
            Score = Score + rsp[2]
        elif t[i] == 's':
            Score = Score + rsp[0]
        elif t[i] == 'p':
            Score = Score + rsp[1]
    return Score

def strsplit(n, t, k):
    tList = [""] * k
    for i in range(n):
        tList[i % k] = tList[i % k] + t[i]
    return tList

RSP = [R, S, P]
Answer = 0
for i in range(K):
    Answer = MaxScore(RSP, strsplit(N, T, K)[i]) + Answer

print(MaxScore(RSP,T))

Submission status: Wrong Answer

Solution code:
#149d

def win(n):
	if n=='r':
		return p
	elif n=='s':
		return r
	else:
		return s

n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
score=0
for i in t:
	score += win(i)

#hands=list(t)

for i in range(n):
	if i+k<n:
		if t[i]==t[i+k]:
			score-=win(t[i+k])
			t[i+k].upper()
print(score)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n, k = [int(_) for _ in input().split()]
    r, s, p = [int(_) for _ in input().split()]
    t = input()
    score = 0

    for i in range(k):
        if t[i] == 'r':
            score += p
        elif t[i] == 's':
            score += r
        elif t[i] == 'p':
            score += s

    for i in range(k+1, n):
        if t[i] != t[i-k]:
            if t[i] == 'r':
                score += p
            elif t[i] == 's':
                score += r
            elif t[i] == 'p':
                score += s
        elif i + 1 - 2*k > 0 and t[i] == t[i-2*k]:
            if t[i] == 'r':
                score += p
            elif t[i] == 's':
                score += r
            elif t[i] == 'p':
                score += s

    print(score)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n, k = [int(_) for _ in input().split()]
    r, s, p = [int(_) for _ in input().split()]
    t = input()
    score = 0

    for i in range(k):
        if t[i] == 'r':
            score += p
        elif t[i] == 's':
            score += r
        elif t[i] == 'p':
            score += s

    for i in range(k+1, n):
        if t[i] != t[i-k]:
            if t[i] == 'r':
                score += p
            elif t[i] == 's':
                score += r
            elif t[i] == 'p':
                score += s
        elif i + 1 - 2*k > 1 and t[i] == t[i-2*k]:
            if t[i] == 'r':
                score += p
            elif t[i] == 's':
                score += r
            elif t[i] == 'p':
                score += s

    print(score)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

hand = {'r':p, 's':r, 'p':s}
win = {'r':'p', 's':'r', 'p':'s'}

ans = 0
u = []
for i,tt in enumerate(t):
    if i >= k and u[i-k] == win[tt]:
            u.append(tt)
    else:
        u.append(win[tt])
        ans += hand[tt]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

res = [0]*N
hands = ["r", "s", "p"]

for i in range(N):
    res[i] = hands[hands.index(T[i])-1]

for i in range(N):
    if i >= K and res[i-K] == res[i]:
        res[i] = 0

score = R*res.count("r") + S*res.count("s") + P*res.count("p")
print(res)
print(R*res.count("r"), S*res.count("s"), P*res.count("p"))
print(score)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
score = {'r':p, 's':r, 'p':s}
from collections import deque
past = deque([])

ans = 0
for i in range(n):
  past.append(t[i])
  if i < k:
    ans += score[t[i]]
  else:
    if past.popleft() != t[i]:
      ans += score[t[i]]
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
Ti=input()

def point(str1,str2): 
    if str1=="s" and str2=="r":
        return R
    elif str1=="r" and str2=="p":
        return P
    elif str1=="p" and str2=="s":
        return S
    else:
        return 0        

T=[[] for i in range(K)]

for i in range(N):
    T[i%K].append(Ti[i])

ans=0
for i in range(K):
    L=len(T[i])
    DP=[[0]*3 for i in range(L+1)]
    for j in range(L):
        DP[j+1][0]=max(DP[j][1],DP[j][2])+point(T[i][j],"r")
        DP[j+1][1]=max(DP[j][2],DP[j][0])+point(T[i][j],"s")
        DP[j+1][2]=max(DP[j][0],DP[j][1])+point(T[i][j],"p")
        if T[i][j]=="r":
            DP[j+1][0]=0
        elif T[i][j]=="s":
            DP[j+1][1]=0
        elif T[i][j]=="p":
            DP[j+1][2]=0
    ans+=max(DP[L])

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

rows, cols = ceil(n / k), k
ans = 0
for j in range(cols):
    dp = [[0, 0, 0] for _ in range(rows + 1)]
    for i in range(rows):
        ri, si, pi = dp[i]
        if i * k + j < n:
            c = t[i * k + j]
        dp[i + 1][0] = max(si, pi) + r * (c == 's')
        dp[i + 1][1] = max(pi, ri) + s * (c == 'p')
        dp[i + 1][2] = max(ri, si) + p * (c == 'r')
    ans += max(dp[rows])

print(ans)

Submission status: Wrong Answer

Solution code:
[N,K] = list(map(int,input().split()))
[R,S,P] = list(map(int,input().split()))
T = input()

j_l = "rsp"
kachi = lambda k : j_l[ (j_l.find(T[k]) + 2) % 3 ]#勝つ手を表示する

rireki = []#出した手の履歴
score = [0,0,0] #出した手の回数を記録

for i in range(N): 
  if i-K >= 0: #K番目以降
    if kachi(i) != rireki[i-K]: #K回前の出した手と比べて、被ってない時、勝ち手を出す
      score[ (j_l.find(T[i])+ 2) % 3 ] += 1#出した手をスコアに足す
      rireki.append(kachi(i)) #履歴に出した手を加える
      #print(score)
    else: #引き分けの時
      rireki.append(T[i]) #履歴に加えるだけ
      #print(score)
  else: #K番以前
    score[ (j_l.find(T[i])+ 2) % 3 ] += 1 #勝つ手を出すだけ
    rireki.append(kachi(i)) #履歴に加える
    #print(score) 
tortal_score = R*score[0] + S*score[1] + P*score[2]

print(tortal_score)

Submission status: Wrong Answer

Solution code:
[N,K] = list(map(int,input().split()))
[R,S,P] = list(map(int,input().split()))
T = input()

j_l = "rsp"
kachi = lambda k : j_l[ (j_l.find(T[k]) + 2) % 3 ]#勝つ手を表示する

rireki = []#出した手の履歴
score = [0,0,0] #出した手の回数を記録

for i in range(N): 
  if i-K >= 0: #K番目以降
    if kachi(i) != rireki[i-K]: #K回前の出した手と比べて、被ってない時、勝ち手を出す
      score[ (j_l.find(T[i])+ 2) % 3 ] += 1#出した手をスコアに足す
      rireki.append(kachi(i)) #履歴に出した手を加える
      print(score)
    else: #引き分けの時
      rireki.append(T[i]) #履歴に加えるだけ
      print(score)
  else: #K番以前
    score[ (j_l.find(T[i])+ 2) % 3 ] += 1 #勝つ手を出すだけ
    rireki.append(kachi(i)) #履歴に加える
    print(score) 
tortal_score = R*score[0] + S*score[1] + P*score[2]

print(tortal_score)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

# r には p、s には r、p には s で勝てる
#  → r にはP点、s にはR点、p にはS点が入る

ans = 0
ans_T = [0 for i in range(N)]

for i in range(N) :
    if i > K :
        if T[i] == "r" :
            if ans_T[i-K] != "p":
                ans_T[i] = "p"
                ans += P
        elif T[i] == "s" :
            if ans_T[i-K] != "r":
                ans_T[i] = "r"
                ans += R
        else :
            if ans_T[i-K] != "s":
                ans_T[i] = "s"
                ans += S
    else :
        if T[i] == "r" :
            ans_T[i] = "p"
            ans += P
        elif T[i] == "s" :
            ans_T[i] = "r"
            ans += R
        else :
            ans_T[i] = "s"
            ans += S

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
lr, ls, lp = -n, -n, -n
ans = 0

for i in range(n):
    if t[i] == "r":
        if k != i+1-lr:
            ans += p
            lr = i+1
    elif t[i] == "s":
        if k != i+1-ls:
            ans += r
            ls = i+1
    else:
         if k != i+1-lp:
            ans += s
            lp = i+1

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()

def point(aite):
    if aite == "r":
        return p
    elif aite == "s":
        return r
    else:
        return s

ten = t.count('r')*p+t.count('s')*r+t.count('p')*s
lose = []
'''
for i in range(n-k):
    if t[i] == t[i+k] and not i in lose:
        ten -= point(t[i])
        lose.append(i+k)
'''
print(ten)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
st = input()
for i in range(len(st)-k):
    if st[i] == st[i + k]:
        st = st[:i + k]+ 'no' + st[i + k + 1:]
win = r*st.count('s') + s*st.count('p') + p*st.count('r')
print(win)

Submission status: Wrong Answer

Solution code:
n,k   = [int(i) for i in input().split()]
r,s,p = [int(i) for i in input().split()]
t = input()

ans = [0 for i in range(n)]
for i in range(n):
    w = t[i]
    if w=='r':
        ans[i] = p
    elif w=='s':
        ans[i] = r
    else:
        ans[i] = s
        
for i in range(k, n):
    if ans[i]==ans[i-k]:
        ans[i]=0
        
print(sum(ans))

Submission status: Wrong Answer

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

def main():
    N,K = map(int,input().split())
    R,S,P = map(int,input().split())
    T = list(map(str,input()))
    d = {"s":R,"p":S,"r":P}
    s = {"s":"r","p":"s","r":"p"}
    ans = 0
    x = []
    for i in range(K):
        ans += d[T[i]]
        x.append(s[T[i]])

    for i in range(N-K):
        if x[-K] == s[T[K+i]]:
            x.append(T[K+i])
        else:
            ans += d[T[K+i]]
            x.append(s[T[K+i]])
            
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
def janken(you,pre):
  global r,s,p
  if you=="r":
    if pre!=0:
      return 0,p
    else:
      return 1,0
  elif you=="s":
    if pre!=1:
      return 1,r
    else:
      return 2,0
  else:
    if pre!=2:
      return 2,s
    else:
      return 0,0
pre = -1
ans = 0
for i in range(k):
  j = 0
  while i+j < n:
    you = t[i+j]
    pre,add= janken(you,pre)
    ans += add
    j += k
print(ans)

Submission status: Wrong Answer

Solution code:
args=input().split()
N=int(args[0])
K=int(args[1])
args=input().split()
R=int(args[0])
S=int(args[1])
P=int(args[2])
T=input()

resSS=[]
for i in T:
  if i=="r":
    resSS.append(P)
  elif i=="s":
    resSS.append(R)
  else:
    resSS.append(S)

if N>=K:
  for i in range(N-K):
    if T[i+K]==T[i]:
      resSS[i+K]=0
res=0
for i in resSS:
  res+=i
print(res)

Submission status: Wrong Answer

Solution code:
args=input().split()
N=int(args[0])
K=int(args[1])
args=input().split()
R=int(args[0])
S=int(args[1])
P=int(args[2])
T=input()

resSS1=[]
resSS2=[]
for i in T:
  if i=="r":
    resSS1.append(P)
    resSS2.append(P)
  elif i=="s":
    resSS1.append(R)
    resSS2.append(R)
  else:
    resSS1.append(S)
    resSS2.append(S)

if N>=K:
  for i in range(N-K):
    if resSS1[i+K]==resSS1[i]:
      resSS1[i+K]=0
  for i in range(N-K):
    if resSS2[N-1-i-K]==resSS2[N-1-i]:
      resSS2[N-1-i-K]=0
res1=0
res2=0
for i in resSS1:
  res1+=i
for i in resSS2:
  res2+=i
if res1>=res2:
  print(res1)
else:
  print(res2)

Submission status: Wrong Answer

Solution code:
args=input().split()
N=int(args[0])
K=int(args[1])
args=input().split()
R=int(args[0])
S=int(args[1])
P=int(args[2])
T=input()

resSS1=[]
resSS2=[]
for i in T:
  if i=="r":
    resSS1.append(P)
    resSS2.append(P)
  elif i=="s":
    resSS1.append(R)
    resSS2.append(R)
  else:
    resSS1.append(S)
    resSS2.append(S)

if N>=K:
  for i in range(N-K):
    if resSS1[i+K]==resSS1[i]:
      resSS1[i+K]=0
  for i in range(K,N):
    if resSS2[i-K]==resSS2[i]:
      resSS2[i-K]=0
res1=0
res2=0
for i in resSS1:
  res1+=i
for i in resSS2:
  res2+=i
if res1>=res2:
  print(res1)
else:
  print(res2)

Submission status: Wrong Answer

Solution code:
args=input().split()
N=int(args[0])
K=int(args[1])
args=input().split()
R=int(args[0])
S=int(args[1])
P=int(args[2])
T=input()

resSS=[]
for i in T:
  if i=="r":
    resSS.append(P)
  elif i=="s":
    resSS.append(R)
  else:
    resSS.append(S)

if N>=K:
  for i in range(N-K):
    if resSS[i+K]==resSS[i]:
      resSS[i+K]=0

res=0
for i in resSS:
  res+=i
print(res)