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

score = 0
hands = [0]*n

# k made hands
for i in range(0, k):
    if T[i]=="r":
        hands[i]="p"
        score += p
    elif T[i]=="s":
        hands[i]="r"
        score += r
    else:
        hands[i]="s"
        score += s
        
if n//k >= 2:
    #k kara n-k
    for x in range(1, n//k):
        for i in range(k*x, min(k*(x+1), n-k)):
            if T[i]=="r":
                if hands[i-k] != "p":
                    hands[i] = "p"
                    score += p
                else:
                    if T[i+k] == "r":
                        hands[i] = "s"
                    else:
                        hands[i] = "p"

            elif T[i]=="s":
                if hands[i-k] != "r":
                    hands[i] = "r"
                    score += r
                else:
                    if T[i+k] == "s":
                        hands[i] = "p"
                    else:
                        hands[i] = "r"

            else:
                if hands[i-k] != "s":
                    hands[i] = "s"
                    score += s
                else:
                    if T[i+k] == "p":
                        hands[i] = "r"
                    else:
                        hands[i] = "s"

    #rest
    for i in range(min(k*(n//k), n-k), n):
        if T[i]=="r":
            if hands[i-k] != "p":
                hands[i] = "p"
                score += p
        elif T[i]=="s":
            if hands[i-k] != "r":
                hands[i] = "r"
                score += r
        else:
            if hands[i-k] != "s":
                hands[i] = "s"
                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()

score = 0
hands = [0]*n

# k made hands
for i in range(0, k):
    if T[i]=="r":
        hands[i]="p"
        score += p
    elif T[i]=="s":
        hands[i]="r"
        score += r
    else:
        hands[i]="s"
        score += s
if n//k >= 2:
    #k kara n-k
    for x in range(1, n//k):
        for i in range(k*x, min(k*(x+1), n-k)):
            if T[i]=="r":
                if hands[i-k] != "p":
                    hands[i] = "p"
                    score += p
                else:
                    if T[i+k] == "r":
                        hands[i] = "s"
                    else:
                        hands[i] = "p"

            elif T[i]=="s":
                if hands[i-k] != "r":
                    hands[i] = "r"
                    score += r
                else:
                    if T[i+k] == "s":
                        hands[i] = "p"
                    else:
                        hands[i] = "r"

            else:
                if hands[i-k] != "s":
                    hands[i] = "s"
                    score += s
                else:
                    if T[i+k] == "p":
                        hands[i] = "r"
                    else:
                        hands[i] = "s"

    #rest
    for i in range(min(k*(n//k), n-k), n):
        if T[i]=="r":
            if hands[i-k] != "p":
                hands[i] = "p"
                score += p
        elif T[i]=="s":
            if hands[i-k] != "r":
                hands[i] = "r"
                score += r
        else:
            if hands[i-k] != "s":
                hands[i] = "s"
                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()

score = 0
hands = [0]*n

# k made hands
for i in range(0, k):
    if T[i]=="r":
        hands[i]="p"
        score += p
    elif T[i]=="s":
        hands[i]="r"
        score += r
    else:
        hands[i]="s"
        score += s

#k kara n-k
for x in range(1, n//k):
    for i in range(k*x, min(k*(x+1), n-k)):
        if T[i]=="r":
            if hands[i-k] != "p":
                hands[i] = "p"
                score += p
            else:
                if T[i+k] == "r":
                    hands[i] = "s"
                else:
                    hands[i] = "p"

        elif T[i]=="s":
            if hands[i-k] != "r":
                hands[i] = "r"
                score += r
            else:
                if T[i+k] == "s":
                    hands[i] = "p"
                else:
                    hands[i] = "r"

        else:
            if hands[i-k] != "s":
                hands[i] = "s"
                score += s
            else:
                if T[i+k] == "p":
                    hands[i] = "r"
                else:
                    hands[i] = "s"

#rest
for i in range(min(k*(n//k), n-k), n):
    if T[i]=="r":
        if hands[i-k] != "p":
            hands[i] = "p"
            score += p
    elif T[i]=="s":
        if hands[i-k] != "r":
            hands[i] = "r"
            score += r
    else:
        if hands[i-k] != "s":
            hands[i] = "s"
            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()

score = 0
hands = [0]*n

# k made hands
for i in range(0, k):
    if T[i]=="r":
        hands[i]="p"
        score += p
    elif T[i]=="s":
        hands[i]="r"
        score += r
    else:
        hands[i]="s"
        score += s

#k kara n-k
for i in range(k, n-k):
    if T[i]=="r":
        if hands[i-k] != "p":
            hands[i] = "p"
            score += p
        else:
            if T[i+k] == "r":
                hands[i] = "s"
            else:
                hands[i] = "p"

    elif T[i]=="s":
        if hands[i-k] != "r":
            hands[i] = "r"
            score += r
        else:
            if T[i+k] == "s":
                hands[i] = "p"
            else:
                hands[i] = "r"

    else:
        if hands[i-k] != "s":
            hands[i] = "s"
            score += s
        else:
            if T[i+k] == "p":
                hands[i] = "r"
            else:
                hands[i] = "s"

#n-k kara n
for i in range(n-k, n):
    if T[i]=="r":
        if hands[i-k] != "p":
            hands[i] = "p"
            score += p
    elif T[i]=="s":
        if hands[i-k] != "r":
            hands[i] = "r"
            score += r
    else:
        if hands[i-k] != "s":
            hands[i] = "s"
            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()

score = 0
hands = [0]*n

#k made
T0_k = T[0:k]
r0_k = T0_k.count("r") #p
s0_k = T0_k.count("s") #r
p0_k = T0_k.count("p") #s
score += p*r0_k + r*s0_k + s*p0_k

# k made hands
for i in range(0, k):
    if T[i]=="r":
        hands[i]="p"
    elif T[i]=="s":
        hands[i]="r"
    else:
        hands[i]="s"

#k kara n-k
for i in range(k, n-k):
    if T[i]=="r":
        if hands[i-k] != "p":
            hands[i] = "p"
            score += p
        else:
            if T[i+k] == "r":
                hands[i] = "s"
            else:
                hands[i] = "p"

    elif T[i]=="s":
        if hands[i-k] != "r":
            hands[i] = "r"
            score += r
        else:
            if T[i+k] == "s":
                hands[i] = "p"
            else:
                hands[i] = "r"

    else:
        if hands[i-k] != "s":
            hands[i] = "s"
            score += s
        else:
            if T[i+k] == "p":
                hands[i] = "r"
            else:
                hands[i] = "s"

#n-k kara n
for i in range(n-k, n):
    if T[i]=="r":
        if hands[i-k] != "p":
            hands[i] = "p"
            score += p
    elif T[i]=="s":
        if hands[i-k] != "r":
            hands[i] = "r"
            score += r
    else:
        if hands[i-k] != "s":
            hands[i] = "s"
            score += s

print(score)

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
R,S,P=map(int, input().split())
t=tuple(input())
te=[]
ans=0
for i in range(k):
  if t[i]=='r':
    ans+=P
    te.append('p')
  elif t[i]=='s':
    ans+=R
    te.append('r')
  else:
    ans+=S
    te.append('s')
for j in range(k,n):
  if t[j]=='r':
      if te[j-k]!='p' or (te[j-k]=='p' and j+k>=n):
        ans+=P
        te.append('p')
      else:
        te.append('0')
  elif t[j]=='s':
      if te[j-k]!='r' or (te[j-k]=='r' and j+k>=n):
        ans+=R
        te.append('r')
      else:
        te.append('0')
  elif t[j]=='p':
      if te[j-k]!='s' or (te[j-k]=='s' and j+k>=n):
        ans+=S
        te.append('s')
      else:
        te.append('0')
print(ans)
print(te)

Submission status: Wrong Answer

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

#K回前と手が被って得点にならないところは、K回後に得点できる手を選べば良い。 
#例えばK回前がグーで、K回後がパーならばチョキを出すことになる。 
#このような手は必ず１種類以上存在するので何を出すかは考えなくても良い。 
for i in range(N-K):
  if T[K+i] == T[i]:
    T[K+i] = 0#ここで適当な手にしておけば、このK回後には絶対勝てる
print(T)

Submission status: Wrong Answer

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

dp = [0] * (n)

for i in range(n):
    if t[i] == "r":
        dp[i] = p
    elif t[i] == "s":
        dp[i] = r
    elif t[i] == "p":
        dp[i] = s

    if k <= i:
        if dp[i] == dp[i-k]:
            dp[i] = 0

print(sum(dp))

Submission status: Wrong Answer

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

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())[:n]
res = 0
for i in range(k):
    dp = [0, 0, 0]
    idx = i
    while idx < n:
        dp[0], dp[1], dp[2] = max(
            dp[1], dp[2]), max(dp[0], dp[1]), max(dp[0], dp[1])
        if t[idx] == 's':
            dp[0] += r
        elif t[idx] == 'p':
            dp[1] += s
        else:
            dp[2] += p
        idx += k
    res += max(dp)
print(res)

Submission status: Wrong Answer

Solution code:
import math
import sys

n, k = map(int, sys.stdin.readline().rstrip().split())
r, s, p = map(int, sys.stdin.readline().rstrip().split())
t = sys.stdin.readline().rstrip()
ans = 0
sim = []
for i, ti in enumerate(t):
    if ti == 'r':
        if i >= k and sim[i - k] == 'p':
            sim.append('x')
        else:
            ans += p
            sim.append('p')
    elif ti == 's':
        if i >= k and sim[i - k] == 'r':
            sim.append('x')
        else:
            ans += r
            sim.append('r')
    else:
        if i >= k and sim[i - k] == 's':
            sim.append('x')
        else:
            ans += s
            sim.append('s')
print(sim)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

n, k = map(int, sys.stdin.readline().rstrip().split())
r, s, p = map(int, sys.stdin.readline().rstrip().split())
t = sys.stdin.readline().rstrip()
ans = 0
sim = []
for i, ti in enumerate(t):
    if ti == 'r':
        if i >= k and sim[i - k] == p:
            ans += 0
            sim.append(0)
        else:
            ans += p
            sim.append(p)
    elif ti == 's':
        if i >= k and sim[i - k] == r:
            ans += 0
            sim.append(0)
        else:
            ans += r
            sim.append(r)
    else:
        if i >= k and sim[i - k] == s:
            ans += 0
            sim.append(0)
        else:
            ans += s
            sim.append(s)

# print(sim)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

n, k = map(int, sys.stdin.readline().rstrip().split())
r, s, p = map(int, sys.stdin.readline().rstrip().split())
t = sys.stdin.readline().rstrip()
ans = 0
sim = []

for ki in range(k):
    tk = t[ki::k]
    # print(tk)
    sim = []
    for i, ti in enumerate(tk):
        if ti == 'r':
            if i >= 1 and sim[i - 1] == p:
                ans += 0
                sim.append(r)
            else:
                ans += p
                sim.append(p)
        elif ti == 's':
            if i >= 1 and sim[i - 1] == r:
                ans += 0
                sim.append(s)
            else:
                ans += r
                sim.append(r)
        else:
            if i >= 1 and sim[i - 1] == s:
                ans += 0
                sim.append(p)
            else:
                ans += s
                sim.append(s)
    # print(sim)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

n, k = map(int, sys.stdin.readline().rstrip().split())
r, s, p = map(int, sys.stdin.readline().rstrip().split())
t = sys.stdin.readline().rstrip()
ans = 0
sim = []
for i, ti in enumerate(t):
    if ti == 'r':
        if i >= k and sim[i - k] == p:
            ans += 0
            sim.append(r)
        else:
            ans += p
            sim.append(p)
    elif ti == 's':
        if i >= k and sim[i - k] == r:
            ans += 0
            sim.append(s)
        else:
            ans += r
            sim.append(r)
    else:
        if i >= k and sim[i - k] == s:
            ans += 0
            sim.append(p)
        else:
            ans += s
            sim.append(s)
# print(sim)
print(ans)

Submission status: Wrong Answer

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

    point = 0
    elec = ['-1'] * n
    for i in range(n):
        if t[i] == 'r':
            if i - k < 0:
                point += p
                elec[i] = 'p'
            else:
                if elec[i - k] == 'p':
                    elec[i] = 'r'
                else:
                    point += p
                    elec[i] = 'p'
        elif t[i] == 's':
            if i - k < 0:
                point += r
                elec[i] = 'r'
            else:
                if elec[i - k] == 'r':
                    elec[i] = 's'
                else:
                    point += r
                    elec[i] = 'r'
        else:
            if i - k < 0:
                point += s
                elec[i] = 's'
            else:
                if elec[i - k] == 's':
                    elec[i] = 'p'
                else:
                    point += s
                    elec[i] = 's'
    print(point)

Submission status: Wrong Answer

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

ans = 0
point_dict = {'r': p, 's': r, 'p': s }
for i in range(k):
    t_x = t[i::k]
    point_0 = 0
    point_1 = 0
    if len(t_x) > 1:
        for j in range(len(t_x)):        
            if (j % 2) == 0:
                if (t_x[j] != t_x[j - 1 if j - 1 >= 0 else 1]) & (t_x[j] != t_x[j + 1 if j + 1 < len(t_x) else len(t_x) - 1]):
                    point_0 += point_dict[t_x[j]]
                point_1 += point_dict[t_x[j]]
            else:
                if (t_x[j] != t_x[j - 1 if j - 1 >= 0 else 1]) & (t_x[j] != t_x[j + 1 if j + 1 < len(t_x) else len(t_x) - 1]):
                    point_1 += point_dict[t_x[j]]
                point_0 += point_dict[t_x[j]]
        ans += max(point_0, point_1)
    else:
        ans += point_dict[t_x[0]]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K =map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
takahashi = [0]*N
ans = 0
for i in range(N):
    janken = ['r', 's', 'p']         
    if i >= K:
        janken.remove(takahashi[i-K])
        
    if T[i] == 'r':
        if 'p' in janken:
            takahashi[i] = 'p'
            ans += P
        else:
            takahashi[i] = 'r'
    elif T[i] == 's':
        if 'r' in janken:
            takahashi[i]= 'r'
            ans += R
        else:
            takahashi[i] = 's'
    elif T[i] == 'p':
        if 's' in janken:
            takahashi[i] = 's'
            ans += S
        else:
            takahashi[i] = 'p'

print(ans)

Submission status: Wrong Answer

Solution code:
N, K =map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
takahashi = [0]*N
ans = 0
for i in range(N):
    janken = ['r', 's', 'p']         
    if i >= K:
        janken.remove(takahashi[i-K])
        
    if T[i] == 'r':
        if 'p' in janken:
            takahashi[i] = 'p'
            ans += P
        else:
            takahashi[i] = 'r'
    elif T[i] == 's':
        if 'r' in janken:
            takahashi[i]= 'r'
            ans += R
        else:
            takahashi[i] = 's'
    elif T[i] == 'p':
        if 's' in janken:
            takahashi[i] = 's'
            ans += S
        else:
            takahashi[i] = 'p'

print(takahashi)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# D

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

# Kのあまりごとに独立して計算する
ans = 0
num = N // K + 1


def vic_sol(s):
    if s == 'r':
        return 2
    if s == 's':
        return 0
    if s == 'p':
        return 1


def ret_score(mine, i, mod, past_rsp):
    sol = vic_sol(T[i * K + mod])
    if (mine == sol) and (sol != past_rsp):
        return score[sol]
    else:
        return 0


for mod in range(K):
    dp = [[0] * 3 for _ in range(num+1)]
    ret = 0
    # 0: R, 1: S, 2: P
    for i in range(1, num):
        if (i-1) * K + mod >= N:
            break
            
        dp[i][0] = max(dp[i-1][1] + ret_score(0, i-1, mod, 1), dp[i-1][2] + ret_score(0, i-1, mod, 2))
        dp[i][1] = max(dp[i-1][0] + ret_score(1, i-1, mod, 0), dp[i-1][2] + ret_score(1, i-1, mod, 2))
        dp[i][2] = max(dp[i-1][0] + ret_score(2, i-1, mod, 0), dp[i-1][1] + ret_score(2, i-1, mod, 1))

        if mod == 0:
            dp[i][0] = max(dp[i][0], dp[i - 1][0] + ret_score(0, i - 1, mod, 0))
            dp[i][1] = max(dp[i][1], dp[i - 1][1] + ret_score(1, i - 1, mod, 1))
            dp[i][2] = max(dp[i][2], dp[i - 1][2] + ret_score(2, i - 1, mod, 2))

        ret = max(ret, dp[i][0], dp[i][1], dp[i][2])
    # print(dp)
    ans += ret

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# D

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

# Kのあまりごとに独立して計算する
ans = 0
num = N // K + 1


def vic_sol(s):
    if s == 'r':
        return 2
    if s == 's':
        return 0
    if s == 'p':
        return 1


def ret_score(mine, i, mod, past_rsp):
    sol = vic_sol(T[i * K + mod])
    if (mine == sol) and (sol != past_rsp):
        return score[sol]
    else:
        return 0


for mod in range(K):
    dp = [[0] * 3 for _ in range(num+1)]
    ret = 0
    # 0: R, 1: S, 2: P
    for i in range(1, num):
        if (i-1) * K + mod >= N:
            break
        dp[i][0] = max(dp[i-1][1] + ret_score(0, i-1, mod, 1), dp[i-1][2] + ret_score(0, i-1, mod, 2))
        dp[i][1] = max(dp[i-1][0] + ret_score(1, i-1, mod, 0), dp[i-1][2] + ret_score(1, i-1, mod, 2))
        dp[i][2] = max(dp[i-1][0] + ret_score(2, i-1, mod, 0), dp[i-1][1] + ret_score(2, i-1, mod, 1))

        ret = max(ret, dp[i][0], dp[i][1], dp[i][2])
    # print(dp)
    ans += ret

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
r=T.count('s')
s=T.count('p')
p=T.count('r')
value=r*R+s*S+p*P
n=0
m=0
for i in range(N-K):
  if T[i]==T[i+K] and (n!=i or m==i):
    n =i+K
    m =i+2*K
    if T[i]=='p':
      value -= S
    elif T[i]=='r':
      value -= P
    else:
      value -= R
print(value)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r = [int(i) for i in input().split()]
t = list(input())
def func(d,ans):
    if d==0:
        ans += r[2]
        dasite.append(2)
    elif d==1:
        ans += r[0]
        dasite.append(0)
    else:
        ans += r[1]
        dasite.append(1)
    return ans

for i in range(n):
    if t[i]=='r':
        t[i]=0
    elif t[i]=='s':
        t[i]=1
    else:
        t[i]=2
#グーを０にチョキを１にパーを2に書き換える
ans = 0
dasite = []
for i in range(n):
    if i<k:
        ans = func(t[i],ans)
    elif i>=n-k:
        if dasite[i-k]==(t[i]+2)%3:
            continue
        else:
            ans = func(t[i],ans)
    else:
        if dasite[i-k]==(t[i]+2)%3:
            if t[i]==t[i+k]:
                dasite.append(t[i])
            elif t[i]==(t[i+k]+1)%3:
                dasite.append((t[i+k]+1)%3)
            else:
                dasite.append(t[i])
        else:
            ans = func(t[i],ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r = [int(i) for i in input().split()]
t = list(input())
def func(d,ans):
    if d==0:
        ans += r[2]
        dasite.append(2)
    elif d==1:
        ans += r[0]
        dasite.append(0)
    else:
        ans += r[1]
        dasite.append(1)
    return ans

for i in range(n):
    if t[i]=='r':
        t[i]=0
    elif t[i]=='s':
        t[i]=1
    else:
        t[i]=2
#グーを０にチョキを１にパーを2に書き換える
ans = 0
dasite = []
for i in range(n):
    if i<k:
        ans = func(t[i],ans)
    elif i>=n-k:
        if dasite[i-k]==(t[i]+2)%3:
            print(i,t[i])
            continue
        else:
            ans = func(t[i],ans)
    else:
        if dasite[i-k]==(t[i]+2)%3:
            if t[i]==t[i+k]:
                dasite.append(t[i])
            elif t[i]==(t[i+k]+1)%3:
                dasite.append((t[i+k]+1)%3)
            else:
                dasite.append(t[i])
        else:
            ans = func(t[i],ans)
print(ans)

Submission status: Wrong Answer

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

for i in range(len(T)):
  if T[i]=='r':
    rc+=1
  elif T[i]=='s':
    sc+=1
  else:
    pc+=1
for j in range(0,N//K-1,2):
  for i in range(K*j,K*(j+1)):
    if T[i]==T[i+K] and T[i]=='r':
      rc-=1
    elif T[i]==T[i+K] and T[i]=='s':
      sc-=1
    elif T[i]==T[i+K] and T[i]=='p':
      pc-=1
  print(j)
a=rc*P+sc*R+pc*S

print(a)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
rc=0
sc=0
pc=0
print(T)
for i in range(len(T)):
  if T[i]=='r':
    rc+=1
  elif T[i]=='s':
    sc+=1
  else:
    pc+=1
for j in range(0,N//K-1,2):
  for i in range(K*j,K*(j+1)):
    if T[i]==T[i+K] and T[i]=='r':
      rc-=1
    elif T[i]==T[i+K] and T[i]=='s':
      sc-=1
    elif T[i]==T[i+K] and T[i]=='p':
      pc-=1

a=rc*P+sc*R+pc*S

print(a)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T=input()
count=0
RSP={"r" : P, "s" : R, "p" : S}
for i in range(N):
    if (i//K)%2==0<K:
        count+=RSP[T[i]]
    else:
        if i+K<N:
            if T[i]!=T[i-K] and T[i]!=T[i+K]:
                count+=RSP[T[i]]
        else:
            if T[i]!=T[i-K]:
                count+=RSP[T[i]]

print(count)

Submission status: Wrong Answer

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

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

t = input()

t=list(t)

memo = []

score = 0

for i in range(n):
    if len(memo) < k:
        if t[i] == 's':
            score += r
            memo.append('r')
        elif t[i] == 'p':
            score += s
            memo.append('s')
        elif t[i] == 'r':
            score += p
            memo.append('p')
        #print(memo)
    else:
        if t[i] == 's':
            if memo[-k] != 'r':
                score += r
                memo.append('r')
            else:
                memo.append('s')
        elif t[i] == 'p':
            if memo[-k] != 's':
                score += s
                memo.append('s')
            else:
                memo.append('p')
        elif t[i] == 'r':
            if memo[-k] != 'p':
                score += p
                memo.append('p')
            else:
                memo.append('r')
print(score)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
takahashiHand =[]
ans = 0

for i in range(k):
    if t[i] == "r":
        takahashiHand.append("p")
    elif t[i] == "s":
        takahashiHand.append("r")
    elif t[i] == "p":
        takahashiHand.append("s")

for i in range(k, n):
    if t[i] == "r" and takahashiHand[i-k] == "p":
        takahashiHand.append(0)
    elif t[i] == "r" and takahashiHand[i-k] != "p":
        takahashiHand.append("p")
    elif t[i] == "s" and takahashiHand[i-k] == "r":
        takahashiHand.append(0)
    elif t[i] == "s" and takahashiHand[i-k] != "r":
        takahashiHand.append("r")
    elif t[i] == "p" and takahashiHand[i-k] == "s":
        takahashiHand.append(0)
    elif t[i] == "p" and takahashiHand[i-k] != "s":
        takahashiHand.append("s")

print(takahashiHand)
ans = r*takahashiHand.count("r") + s*takahashiHand.count("s") + p*takahashiHand.count("p")
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i, t in enumerate(ts):
  if t == "r":
    if not i - k < 0:
      if hands[i - k] == "p":
        ans += 0
        hands.append(t)
        continue
    ans += p
    hands.append("p")
  elif t == "s":
    if not i - k < 0:
      if hands[i - k] == "r":
        ans += 0
        hands.append(t)
        continue
    ans += r
    hands.append("r")
  elif t == "p":
    if not i - k < 0:
      if hands[i - k] == "s":
        ans += 0
        hands.append(t)
        continue
    ans += s
    hands.append("s")

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
A=str(input())
T2=""
for i in range(K):
  m=1
  while i+K<=N-1:
    if i+2*K>N-1:
      if A[i]!=A[i+K]:
        T2+=((m-1)//2+1)*str(A[i])+str(A[i+K])
      else:
        m+=1
        T2+=((m-1)//2+1)*str(A[i])
    else:
      if A[i]!=A[i+K]:
        T2+=((m-1)//2+1)*str(A[i])
        m=1
      else:
        m+=1
    i+=K
point=0
for j in T2:
  if j=="r":
    point+=P
  elif j=="p":
    point+=S
  else:
    point+=R
print(point)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())
A=[]
for j in range(len(T)):
  if T[j]=="r":
    A.append("P")
  elif T[j]=="s":
    A.append("R")
  else:
    A.append("S")
T2=""
for i in range(K):
  m=1
  while i+K<=N-1:
    if i+2*K>N-1:
      if A[i]!=A[i+K]:
        T2+=((m-1)//2+1)*str(A[i])+str(A[i+K])
      else:
        m+=1
        T2+=((m-1)//2+1)*str(A[i])
    else:
      if A[i]!=A[i+K]:
        T2+=((m-1)//2+1)*str(A[i])
        m=1
      else:
        m+=1
    i+=K
point=0
for j in T2:
  if j=="P":
    point+=P
  elif j=="S":
    point+=S
  else:
    point+=R
print(point)

Submission status: Wrong Answer

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

# d={'r':0,'s':0,'p':0}
d={}
ans=0
c=0
for i in t:

    if c >= k:
        x =d[c-k]
        if i =='r':
            if x == 'p':
                d[c]='r'
            else:
                ans += p ; d[c]='p'
        elif i == 's': 
            if x == 'r':
                d[c]='s'
            else:
                ans += r;d[c]='r'
        elif i == 'p': 
            if x == 's':
                d[c]='p'
            else:
                ans += s;d[c]='s'

    else:
        if i =='r':
            ans += p ; d[c]='p'
        elif i == 's': 
            ans += r;d[c]='r'
        elif i == 'p': 
            ans += s;d[c]='s'

    c+=1


print(ans)

Submission status: Wrong Answer

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

# g=r点 t=s点 p=p点
ans = 0
for i in range(n):
    if t[i] == "r":
        if i >= k and t[i - k] == "r":
            t[i] = 'm'#iの手以外の手
        else:
            ans += p
    if t[i] == "t":
        if i >= k and t[i - k] == "t":
            t[i] = 'm'
        else:
            ans += r
    if t[i] == "p":
        if i >= k and t[i - k] == "p":
            t[i] = 'm'
        else:
            ans += s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,K = (int(x) for x in input().split())
R,S,P = (int(x) for x in input().split())
T = input()
count = 0
prog = 0
checker = ""
l = list(T)
d = deque(l)
for hand in l:
    if prog >= K:
        if hand == "r" and hand != checker:
            count += P
            checker = d.popleft()
        elif hand == "s" and hand != checker:
            count += R
            checker = d.popleft()
        elif hand == "p" and hand != checker:
            count += S
            checker = d.popleft()
        else:
            checker = d.popleft() + " "
    else:
        prog += 1
        if hand == "r":
            count += P
        elif hand == "s":
            count += R
        else:
            count += S
        if prog >= K:
            checker = d.popleft()
print(count)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
l=[0]*n #得点の列
for i in range(n):
  if t[i]=="r":
    l[i]=p
  elif t[i]=="s":
    l[i]=r
  else:
    l[i]=s
    
res=0
for i in range(n):
  if i>k-1 and l[i-k]==l[i]:
    l[i]=0
  res+=l[i]
  
print(res)