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:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    win_hands = [0] * N
    for index, t in enumerate(T):
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S
        if index >= K and win_hands[index] == win_hands[index - K]:
            win_hands[index] = 0

    print(sum(win_hands))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    win_hands = [0] * N
    for index, t in enumerate(T):
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S

    for i in range(K, N):
        if win_hands[i] == win_hands[i - K]:
            win_hands[i] = 0
    print(sum(win_hands))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    win_hands = [0] * N
    for index, t in enumerate(T):
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S

    for i in range(K - 1, N):
        if win_hands[i] == win_hands[i - K]:
            win_hands[i] = 0
    print(sum(win_hands))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())

    win_hands = [0] * N
    for index, t in enumerate(T):
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S

    cumsum = 0
    for i in range(N):
        if i >= K and win_hands[i] == win_hands[i - K]:
            win_hands[i] = 0
        else:
            cumsum += win_hands[i]
    print(cumsum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    win_hands = [0] * N
    for index, t in enumerate(T):
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S

    cumsum = 0
    for i in range(N):
        if i >= K and win_hands[i] == win_hands[i - K]:
            win_hands[i] = 0
        else:
            cumsum += win_hands[i]
    print(cumsum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    win_hands = [0] * N
    for index, t in enumerate(T):
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S

    cumsum = 0
    for i in range(N):
        if i >= K and win_hands[i] == win_hands[i - K]:
            win_hands[i] = -1
        else:
            cumsum += win_hands[i]
    print(cumsum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    win_hands = [0] * N
    for index, t in enumerate(T):
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S

    # dp[i][j]はi回目の勝敗がjの時の最高得点
    is_win = [True] * N
    cumsum = 0
    for i in range(N):
        if (1
                and i >= K
                and win_hands[i] == win_hands[i - K]
                and is_win[i - K] is True):
            is_win[i] = False
        else:
            cumsum += win_hands[i]
    print(cumsum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    win_hands = [0] * N
    for index, t in enumerate(T):
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S

    # dp[i][j]はi回目の勝敗がjの時の最高得点
    dp = [-1] * N
    is_win = [True] * N
    dp[0] = win_hands[0]
    for i in range(1, N):
        if (1
                and i >= K
                and win_hands[i] == win_hands[i - K]
                and is_win[i - K] is True):
            dp[i] = dp[i - 1]
            is_win[i] = False
        else:
            dp[i] = dp[i - 1] + win_hands[i]
    print(dp[-1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    win_hands = [-1] * N
    index = 0
    for t in T:
        if t == 'r':
            win_hands[index] = P
        elif t == 's':
            win_hands[index] = R
        else:
            win_hands[index] = S
        index += 1

    # dp[i][j]はi回目の勝敗がjの時の最高得点
    # dp = np.zeros((N, 1), dtype=np.int64)
    dp = [[-1] * 2 for _ in range(N)]
    dp[0] = [win_hands[0], 1]
    for i in range(1, N):
        if i < K:
            dp[i] = [dp[i - 1][0] + win_hands[i], 1]
        else:
            if win_hands[i] == win_hands[i - K]:
                if dp[i - K][-1] == 1:
                    dp[i] = [dp[i - 1][0], 0]
                else:
                    dp[i] = [dp[i - 1][0] + win_hands[i], 1]
            else:
                dp[i] = [dp[i - 1][0] + win_hands[i], 1]
    print(dp[-1][0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
r, s, p = map(int, input().split())
T = list(str(input()))
ans = 0
S = [-1]*n
for i in range(n):
    if i <= k-1:
        if T[i] == 'r':
            S[i] = 'p'
            ans += p
        elif T[i] == 's':
            S[i] = 'r'
            ans += r
        else:
            S[i] = 's'
            ans += s
    else:
        if T[i] == 'r':
            if S[i-k] != 'p':
                S[i] = 'p'
                ans += p
            else:
                if i+k <= n-1:
                    if T[i+k] == 's':
                        S[i] = 's'
                    elif T[i+k] == 'p':
                        S[i] = 'r'
                    else:
                        S[i] = 's'
                else:
                    S[i] = 'r'
        elif T[i] == 's':
            if S[i-k] != 'r':
                S[i] = 'r'
                ans += r
            else:
                if i+k <= n-1:
                    if T[i+k] == 's':
                        S[i] = 'p'
                    elif T[i+k] == 'r':
                        S[i] = 's'
                    else:
                        S[i] = 's'
                else:
                    S[i] = 's'
        else:
            if S[i-k] != 's':
                S[i] = 's'
                ans += s
            else:
                if i+k <= n-1:
                    if T[i+k] == 's':
                        S[i] = 'p'
                    elif T[i+k] == 'r':
                        S[i] = 'r'
                    else:
                        S[i] = 'p'
                else:
                    S[i] = 'p'
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()
    scores = []
    for t in T:
        if t == 'r':
            scores.append(P)
        elif t == 's':
            scores.append(R)
        else:
            scores.append(S)
    for i in range(N-K):
        if scores[i] == scores[i+K]:
            scores[i+K] = 0
    print(sum(scores))


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()
if T[0] == 'r':
  ans = P
elif T[0] == 's':
  ans = R
else:
  ans = S
for i in range(1,N):
  if N//i%2 == 0:
    if T[i] == 'r':
      ans += P
    elif T[i] == 's':
      ans += R
    else:
      ans += S
  else:
    if T[i] != T[i-K] and T[i] == 'r':
      ans += P
    elif T[i] != T[i-K] and T[i] == 's':
      ans += R
    elif T[i] != T[i-K]:
      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()
ans=0
for i in range(k):
  cnt=1
  dict={'r':0,'s':0,'p':0}
  if t[i]=='r':
    ans+=p
  elif t[i]=='s':
    ans+=r
  elif t[i]=='p':
      ans+=s
  while i+cnt*k<n:
    if t[i+(cnt-1)*k]==t[i+cnt*k]:
      dict[t[i+cnt*k]]+=1
    else:
      if t[i+cnt*k]=='r':
        ans+=p
      elif t[i+cnt*k]=='s':
        ans+=r
      elif t[i+cnt*k]=='p':
        ans+=s
    cnt+=1
  for j in dict:
    if j=='r':
      ans+=p*(dict[j]//2)
    elif j=='s':
      ans+=r*(dict[j]//2)
    elif j=='p':
      ans+=s*(dict[j]//2)
print(ans)

Submission status: Wrong Answer

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


# グー   (R) = 0
# チョキ (S) = 1
# パー   (P) = 2


def solve1(T, points):
    """K = 1として解く"""
    dp_0 = [-1, -1, -1]
    dp_1 = [-1, -1, -1]
    # 最初の手
    for h in range(3):
        if (h + 1) % 3 == T[0]:  # 自分の手が R で相手が S など勝てるパタン
            dp_0[h] = points[h % 3]
        else:
            dp_0[h] = 0
    # 2手目以降
    for t in T[1:]:
        for h in range(3):
            # 前の手は今回の手とちがわなくては行けない
            h0_a = (h + 1) % 3
            h0_b = (h + 2) % 3
            # 今回のポイント
            if (h + 1) % 3 == t:  # 自分の手が R で相手が S など勝てるパタン
                p1 = points[h % 3]
            else:
                p1 = 0
            dp_1[h] = max(dp_0[h0_a], dp_0[h0_b]) + p1
        dp_0 = dp_1.copy()

    return max(dp_1)

def solve(
    N: int, K: int, R_point: int, S_point: int, P_point: int, T: str
):
    # とする
    mapping = {"r": 0, "s": 1, "p": 2}
    points = [R_point, S_point, P_point]
    T = [mapping[t] for t in T]
    answer = 0
    for ofs in range(K):
        answer += solve1(T[ofs::K], points)

    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    R_point = int(next(tokens))  # type: int
    S_point = int(next(tokens))  # type: int
    P_point = int(next(tokens))  # type: int
    T = next(tokens)  # type: str
    answer = solve(N, K, R_point, S_point, P_point, T)
    print(answer)


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()

w1=''
w2=''
ans=0
for i in range(N):
    if T[i]=='r':
        w1+='p'
    elif T[i]=='p':
        w1+='s'
    else:
        w1+='r'

for i in range(0,K):
    if T[i]=='r':
        w2+='p'
        ans+=P
    elif T[i]=='p':
        w2+='s'
        ans+=S
    else:
        w2+='r'
        ans+=R

if N>2:
    for i in range(K,N):
        if w1[i]==w2[i-K]:
            w2+='_'
        else:
            if w1[i]=='p':
                w2+='p'
                ans+=P
            elif w1[i]=='s':
                w2+='s'
                ans+=S
            else:
                w2+='r'
                ans+=R
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
r, s, p =map(int,input().split())
t = list(input())
wins = []
cnt = 0
minus = 0
for out in t:
    if out == "r":
        wins.append(p)
    elif out == "s":
        wins.append(r)
    else:
        wins.append(s)
    if cnt > k - 1:
        if wins[cnt] == wins[cnt-k]:
                wins[cnt] = 0
    cnt = cnt + 1

print(sum(wins))

Submission status: Wrong Answer

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

machine = {}
cnt = 0
r,s,p = p,r,s
hands = (r,s,p)

for i in t:
  cnt += 1
  i = r if i=='r' else s if i=='s' else p
  machine[cnt] = i

score = 0

for i in range(1, n+1):
  if i > k and machine[i] == machine[i-k]:
      if i+k <= n and  machine[i+k] != machine[i]:
        continue
      else:
        if machine[i] == max(hands):
          machine[i] = sum(hands) - max(hands) - min(hands)
        else:
          machine[i] = max(hands)
  else:
    score += machine[i]

print(score)

Submission status: Wrong Answer

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

T_split = [[] for i in range(K)]
for i in range(N):
    if T[i] == 'r':
        point = P
    elif T[i] == 's':
        point = R
    elif T[i] == 'p':
        point = S
    T_split[i%K].append(point)
#print(T_split)

ans = 0
flag = 0

for i in range(len(T_split)):
    flag = 0
    for j in range(len(T_split[i])):
        if flag == 1:
            flag = 0
            continue
        ans += T_split[i][j]
        if j != len(T_split[i]) - 1:
            if T_split[i][j] == T_split[i][j+1]:
                flag = 1
print(ans)

Submission status: Wrong Answer

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



T_split = [[] for i in range(K)]
for i in range(N):
    if T[i] == 'r':
        point = P
    elif T[i] == 's':
        point = R
    elif T[i] == 'p':
        point = S
    T_split[i%K].append(point)
#print(T_split)

ans = 0
flag = 0

for i in range(len(T_split)):
    for j in range(len(T_split[i])):
        if flag == 1:
            flag = 0
            continue
        ans += T_split[i][j]
        if j != len(T_split[i]) - 1:
            if T_split[i][j] == T_split[i][j+1]:
                flag = 1
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Prediction and Restriction 
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()

# じゃんけんの勝敗を返す関数
def judge(a,b):
    if a == 'r' and b == 2:
        return True
    elif a == 's' and b == 0:
        return True
    elif a == 'p' and b == 1:
        return True
    return False

# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]

# v 回目のじゃんけん
for v in range(1,N+1):
    # v 回目に出した手
    for w in range(3):
        # v-K 回目に出した手 
        for k in range(3):
            if w == k:
                continue
            # じゃんけんで勝ったとき
            if judge(T[v-1],w):
                dp[v][w] = max(dp[v][w],dp[v-K][k] + RSP[w])
            # じゃんけんで負けか引き分けたとき
            dp[v][w] = max(dp[v][w],dp[v-K][k])
            print('v,w,k',v,w,k,dp)
print(dp)               
# K 個に分けた各グループの部分和の最大値の総和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Prediction and Restriction 
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()

# じゃんけんの勝敗を返す関数
def judge(a,b):
    if a == 'r' and b == 2:
        return True
    elif a == 's' and b == 0:
        return True
    elif a == 'p' and b == 1:
        return True
    return False

# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]

# K 以下の数字について
for v in range(1,K+1):
    # w = v, v+K, v+2K,...
    for w in range(v,N+1,K):
        # w 回目に出した手
        for l in range(3):
            # w-K 回目に出した手 
            for m in range(3):
                if l == m:
                    continue
                # じゃんけんで勝ったとき
                if judge(T[w-1],l):
                    dp[w][l] = max(dp[w][l],dp[w-K][m] + RSP[l])
                # じゃんけんで負けか引き分けたとき
                else:
                    dp[w][l] = max(dp[w][l],dp[w-K][m])      
# K 個に分けた各グループの部分和の最大値の総和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Prediction and Restriction 
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()

# じゃんけんの勝敗を返す関数
def judge(a,b):
    if a == 'r' and b == 2:
        return True
    elif a == 's' and b == 0:
        return True
    elif a == 'p' and b == 1:
        return True
    return False

# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]

# K 以下の数字について
for v in range(1,K+1):
    # w = v, v+K, v+2K,...
    for w in range(v,N+1,K):
        # w 回目に出した手
        for l in range(3):
            # w-K 回目に出した手 
            for m in range(3):
                if l == m:
                    continue
                # じゃんけんで勝ったとき
                if judge(T[w-1],l):
                    dp[w][l] = max(dp[w][l],dp[w-K][m] + RSP[l])
                # じゃんけんで負けか引き分けたとき
                else:
                    dp[w][l] = max(dp[w][l],dp[w-K][m])
print(dp)               
# K 個に分けた各グループの部分和の最大値の総和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Prediction and Restriction 
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()

# じゃんけんの勝敗を返す関数
def judge(a,b):
    if a == 'r' and b == 2:
        return True
    elif a == 's' and b == 0:
        return True
    elif a == 'p' and b == 1:
        return True
    return False

# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]

# K 以下の数字について
for v in range(1,K+1):
    # w = v, v+K, v+2K,...
    for w in range(v,N+1,K):
        # w 回目に出した手
        for l in range(3):
            # w-K 回目に出した手 
            for m in range(3):
                if l == m:
                    continue
                # じゃんけんで勝ったとき
                if judge(T[w-1],l):
                    dp[w][l] = max(dp[w][l],dp[w-K][m] + RSP[l])
                # じゃんけんで負けたとき
                dp[w][l] = max(dp[w][l],dp[w-K][m])

# K 個に分けた各グループの部分和の最大値の和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Prediction and Restriction 
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()

# じゃんけんの勝敗を返す関数
def judge(a,b):
    if a == 'r' and b == 2:
        return True
    elif a == 's' and b == 0:
        return True
    elif a == 'p' and b == 1:
        return True
    return False

# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]

# K 以下の数字について
for v in range(1,K+1):
    # w = v, v+K, v+2K,...
    for w in range(v,N+1,K):
        # w 回目に出した手
        for l in range(3):
            # w-K 回目に出した手 
            for m in range(3):
                if l == m:
                    continue
                # じゃんけんで勝ったとき
                if judge(T[w-1],l):
                    dp[w][l] = max(dp[w][l],dp[w-K][m] + RSP[l])
                # じゃんけんで負けたとき
                dp[w][l] = max(dp[w][l],dp[w-K][m])
print(dp)               
# K 個に分けた各グループの部分和の最大値の和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Prediction and Restriction (hint)
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()

# じゃんけんの勝敗を返す関数
def judge(a,b):
    if a == 'r' and b == 2:
        return True
    elif a == 's' and b == 0:
        return True
    elif a == 'p' and b == 1:
        return True
    return False

# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]

# K 以下の数字について
for v in range(1,K+1):
    # w = v, v+K, v+2K,...
    for w in range(v,N+1,K):
        # w 回目に出した手
        for l in range(3):
            # w-K 回目に出した手 
            for m in range(3):
                if l == m:
                    continue
                # じゃんけんで勝ったとき
                if judge(T[w-1],l):
                    dp[w][l] = max(dp[w][l],dp[w-K][m] + RSP[l])
                # じゃんけんで負けたとき
                dp[w][l] = max(dp[w][l],dp[w-K][m])
                
# K 個に分けた各グループの部分和の最大値の和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
wins = {"p":"s", "r":"p", "s":"r"}
points = {"p":S, "r":P, "s":R}
hands = []

ans = 0
for i in range(N):
    if i - K < 0:
        hands.append(wins[T[i]])
        ans += points[T[i]]
    else:
        if hands[i-K] == wins[T[i]]:
            #あいこにするしか無い時
            hands.append(T[i])
        else:
            #勝てる時
            hands.append(wins[T[i]])
            ans += points[T[i]]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
wins = {"p":"s", "r":"p", "s":"r"}
points = {"p":S, "r":P, "s":R}
hands = []

ans = 0
for i in range(N):
    if i - K < 0:
        hands.append(wins[T[i]])
        ans += points[T[i]]
    else:
        if hands[i-K] == wins[T[i]]:
            #あいこにするしか無い時
            hands.append(T[i])
        else:
            #勝てる時
            hands.append(wins[T[i]])
            ans += points[T[i]]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

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

    dp = [[0] * 3 for _ in range(n + k)]
    for i1 in range(k):
        i2 = i1 + k
        while i2 - k < n:
            dp[i2][0] = max(dp[i2-k][1], dp[i2-k][2])
            dp[i2][0] += r if t[i2-k] == 's' else 0
            dp[i2][1] = max(dp[i2-k][0], dp[i2-k][2])
            dp[i2][1] += s if t[i2-k] == 'p' else 0
            dp[i2][2] = max(dp[i2-k][0], dp[i2-k][1])
            dp[i2][2] += p if t[i2-k] == 'r' else 0
            i2 += k
    print(*dp, sep='\n')
    r = 0
    for j1 in range(-k, 0, 1):
        r += max(dp[j1])
    print(r)

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()

me = ""

ans = 0

for i in range(n):
    if t[i] == "r":
        if i < k:
            me += "p"
            ans += p
        elif me[i-k] != "p":
            me += "p"
            ans += p
        else:
            me += "r"

    elif t[i] == "s":
        if i < k:
            me += "r"
            ans += r
        elif me[i-k] != "r":
            me += "r"
            ans += r
        else:
            me += "s"

    else:
        if i < k:
            me += "s"
            ans += s
        elif me[i-k] != "s":
            me += "s"
            ans += s
        else:
            me += "p"

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
l=[]
for i in range(K):
    l.append([T[K-i-1]])
for j in range(K,N):
    if l[(j+1)%K][j//K-1]!=T[j]:
        l[(j+1)%K].append(T[j])
    else:
        l[(j+1)%K].append("t")
ans=0
for k in l:
    ans+=k.count("r")*P+k.count("s")*R+k.count("p")*S
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()
last = ["" for _ in range(k)]
move = {"r": "p", "p": "s", "s": "r"}
pts = {"r": r, "p": p, "s": s}
score = 0

res = ""
for i in range(n):
    if move[t[i]] != last[i%k]:
        score += pts[move[t[i]]]
        last[i%k] = move[t[i]]

        res += move[t[i]]
    else:
        last[i%k] = t[i]
        res += t[i]

print(score)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r_origin, s_origin, p_origin = map(int, input().split())
t = '!' + str(input())
def make_rsp(i):
    global t, r_origin, s_origin, p_origin
    r_temp = 0
    s_temp = 0
    p_temp = 0
    if t[i] == 'r':
        p_temp = p_origin
    if t[i] == 's':
        r_temp = r_origin
    if t[i] == 'p':
        s_temp = s_origin
    return r_temp, s_temp, p_temp

rock = [0] * (n + 1)
sissors = [0] * (n + 1)
paper = [0] * (n + 1)
best = [0] * (n + 1)
for i in range(1, n + 1):
    best[i] = max(make_rsp(i))

for i in range(1, k+1):
    m = max(rock[i-1], sissors[i-1], paper[i-1])
    r_temp, s_temp, p_temp = make_rsp(i)
    rock[i] = r_temp + m
    sissors[i] = s_temp + m
    paper[i] = p_temp + m

if k > 1:
    cnt = sum(best[2:k+1])
else:
    cnt = 0

for i in range(k+1, n+1):
    r_temp, s_temp, p_temp = make_rsp(i)
    rb = rock[i-k]
    sb = sissors[i-k]
    pb = paper[i-k]
    rock[i] = r_temp + cnt + max(sb, pb)
    sissors[i] = s_temp + cnt + max(rb, pb)
    paper[i] = p_temp + cnt + max(rb, sb)
    cnt += best[i]
    cnt -= best[i-k+1]

print(max(rock[n], sissors[n], paper[n]))
# print("r", rock)
# print("s", sissors)
# print("p", paper)
# print(best)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
t = list(input())
ans = []
for i in t:
    if i == 'r':
        ans.append(li[2])
    elif i == 's':
        ans.append(li[0])
    else:
        ans.append(li[1])
for i in range(len(ans)):
    if k <= i and ans[i]==ans[i-k]:
        ans[i] =0
print(sum(ans))

Submission status: Wrong Answer

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

ans=0
for i in range(k):
  if t[i]=="r":
    l[i]="p"
    ans+=p
  elif t[i]=="p":
    l[i]="s"
    ans+=s
  else:
    l[i]="r"
    ans+=r

for i in range(k,n):
  if t[i]=="r":
    if l[i-k]!="p":
      l[i]="p"
      ans+=p
    else:
      l[i]="r"
  elif t[i]=="p":
    if l[i-k]!="s":
      ans+=s
      l[i]="s"
    else:
      l[i]="p"
  else:
    if t[i]=="s":
      if l[i-k]!="r":
        ans+=r
        l[i]="r"
      else:
        l[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()
score = {"r":P, "s":R, "p":S} 
m = {"r":"p", "s":"r", "p":"s"}
command= []
mm = []
ans = 0
#添字は0から始まることに注意
#r : 0 s : 1 p : 2

for i in range(N):
    if i - K < 0:
        ans += score[T[i]]
        mm.append(m[T[i]])
    else:
        if m[T[i]] != mm[i-2]:
            ans += score[T[i]]
            mm.append(m[T[i]])
        else:
            mm.append("")
                 
print(ans)

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} 
m = {"r":"p", "s":"r", "p":"s"}
command= []
mm = []
ans = 0

for i in range(N):
    if i <= K-1:
        ans += score[T[i]]
        mm.append(m[T[i]])
    else:
        if m[T[i]] != mm[i-2]:
            ans += score[T[i]]
            mm.append(m[T[i]])
        else:
            mm.append("")
                 
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N,K = LI()
R,S,P = LI()
T = _S()
# R:P点, S:R点, P:S点

point = {'r':P, 's': R, 'p':S}

count = 0
for i in range(K+1):
    # print(point[T[i]])
    count += point[T[i]]
for i in range(K+1,N):
    if not T[i]==T[i-K]:
        # print(point[T[i]])
        count += point[T[i]]
print(count)

# N = I()
#H,N = LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
#Ap = np.array(A)
#C = np.zeros(N + 1)

# if ans:
#     print('Yes')
# else:
#     print('No')

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
R,S,P = map(int,input().split())
points = {'r':P,'s':R,'p':S}
l = list(input())
ans = 0
for i,j in enumerate(l):
  if (i-k<=0) or l[i] != l[i-k]:
    ans += points[j]

print(ans)