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: Accepted

Solution code:
def calc(l):
    n = len(l)
    dp = [[0]*3 for _ in range(n+1)]
    
    for i in range(n):
        if l[i]=='r':
            dp[i+1][0] = max(dp[i][1], dp[i][2])
            dp[i+1][1] = max(dp[i][0], dp[i][2])
            dp[i+1][2] = max(dp[i][0], dp[i][1])+P
        elif l[i]=='s':
            dp[i+1][0] = max(dp[i][1], dp[i][2])+R
            dp[i+1][1] = max(dp[i][0], dp[i][2])
            dp[i+1][2] = max(dp[i][0], dp[i][1])
        else:
            dp[i+1][0] = max(dp[i][1], dp[i][2])
            dp[i+1][1] = max(dp[i][0], dp[i][2])+S
            dp[i+1][2] = max(dp[i][0], dp[i][1])
    
    return max(dp[n])

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0

for i in range(K):
    l = []
    j = i
    
    for j in range(i, N, K):
        l.append(T[j])
    
    ans += calc(l)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, R, S, P, T):
    ans = 0
    s = []
    for i, t in enumerate(T):
        if t == 'r':
            if i - K >= 0 and s[i-K] == 'p':
                s.append('.')
            else:
                s.append('p')
                ans += P
        elif t == 's':
            if i - K >= 0 and s[i-K] == 'r':
                s.append('.')
            else:
                s.append('r')
                ans += R
        elif t == 'p':
            if i - K >= 0 and s[i-K] == 's':
                s.append('.')
            else:
                s.append('s')
                ans += S
    return ans


def main():
    N, K = read_int_n()
    R, S, P = read_int_n()
    T = read_str()
    print(slv(N, K, R, S, P, T))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    r,s,p = LI()
    t = S()
    dp = [[0]*3 for _ in range(k)]
    for i in range(n):
        c = t[i]
        b = -1
        cp = dp[i%k]
        np = cp[:]
        mp = max(cp)
        if c == "r":
            np[2] = max(max(cp[0], cp[1]) + p, cp[2])
            np[1] = np[0] = mp
        elif c == "s":
            np[0] = max(max(cp[2], cp[1]) + r, cp[0])
            np[1] = np[2] = mp
        else:
            np[1] = max(max(cp[2], cp[0]) + s, cp[1])
            np[2] = np[0] = mp

        dp[i%k] = np

    return sum(map(max, dp))


print(main())

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ss=[""]*k
ans=0
for i in range(n):ss[i%k]+=t[i]
for t in ss:
  m=len(t)
  dp=[[0,0,0]for _ in range(m)]
  #rsp
  if t[0]=="r":dp[0]=[0,0,p]
  elif t[0]=="s":dp[0]=[r,0,0]
  else:dp[0]=[0,s,0]
  for i in range(1,m):
    dp[i]=[max(dp[i-1][1],dp[i-1][2]),max(dp[i-1][0],dp[i-1][2]),max(dp[i-1][0],dp[i-1][1])]
    if t[i]=="r":
      dp[i][2]+=p
    if t[i]=="s":dp[i][0]+=r
    if t[i]=="p":dp[i][1]+=s
  ans+=max(dp[-1])
print(ans)

Submission status: Accepted

Solution code:

N,K = map(int,input().split())

R,S,P = map(int,input().split())

T = input()

ans = 0
t = ""

for i in range(N):

    if T[i] == "r":

        if len(t) < K or (len(t) >= K and t[-K] != "P"):
            ans += P
            t += "P"
        else:
            t += "N"

    if T[i] == "s":

        if len(t) < K or (len(t) >= K and t[-K] != "R"):
            ans += R
            t += "R"
        else:
            t += "N"


    if T[i] == "p":

        if len(t) < K or (len(t) >= K and t[-K] != "S"):
            ans += S
            t += "S"
        else:
            t += "N"

print (ans)

Submission status: Accepted

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

n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
ans = 0
D = {"r":p, "s":r, "p":s}
for i in range(n):
    if i-k < 0 or t[i] != t[i-k]:
        ans += D[t[i]]
    else:
        t[i] = "n"
        # print(t)
    # print(i,ans)
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = input()
dict = {'r': p, 's': r, 'p': s}

texts = []
for i in range(k):
    text = T[i::k]
    texts.append(text)

ans = 0
for text in texts:
    prev = ''
    for t in text:
        if t == prev:
            prev = ''
            continue

        else:
            prev = t
            ans += dict[t]

print(ans)

Submission status: Accepted

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

ans = 0
X = ["."]*N
for i in range(N):
  if T[i]=="r" and (i<K or X[i-K]!="p"):
    ans += P
    X[i] = "p"
  if T[i]=="p" and (i<K or X[i-K]!="s"):
    ans += S
    X[i] = "s"
  if T[i]=="s" and (i<K or X[i-K]!="r"):
    ans += R
    X[i] = "r"
print ans

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
count=0
dp=[0]*n
for i in range(n):
    if i<k:
        if t[i]=='r':
            count+=p
        elif t[i]=='s':
            count+=r
        else:
            count+=s
        dp[i]=1
        continue
    if t[i]==t[i-k] and dp[i-k]==1:
        continue
    if t[i]=='r':
        count+=p
    elif t[i]=='s':
        count+=r
    else:
        count+=s
    dp[i]=1
print(count)

Submission status: Accepted

Solution code:


# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

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

ans = 0

for i in range(k):
    tt = t[i::k]
    l = len(tt)
    dpr = dps = dpp = 0
    for i in tt:
        if i == "r":
            dpr,dps,dpp = max(dps,dpp),max(dpr,dpp),max(dps,dpr)+p
        if i == "s":
            dpr,dps,dpp = max(dps,dpp)+r,max(dpr,dpp),max(dps,dpr)
        if i == "p":
            dpr,dps,dpp = max(dps,dpp),max(dpr,dpp)+s,max(dps,dpr)

    ans += max(dpr,dps,dpp)


print(ans)

Submission status: Accepted

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


res = [0 for _ in range(N)]
for i, t in enumerate(T):
    if i - K < 0 or (i - K >= 0 and (res[i - K] == 0 or T[i - K] != T[i])):
        res[i] = point[t]

print(sum(res))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
s = input()
d = {"r" : P, "s" : R, "p" : S}
dd = set()
r = 0
for i in range(N):
    r += d[s[i]]
    if i >= K:
        if i-K not in dd:
            if s[i-K] == s[i]:
                dd.add(i)
                r -= d[s[i]]
print(r)

Submission status: Accepted

Solution code:
N,K=[int(i) for i in input().split(" ")]
R,S,P=[int(i) for i in input().split(" ")]
T=input()


score=0
for i in range(K):
    hand=T[i::K]
    hand=hand.replace("pp","p")
    hand=hand.replace("rr","r")
    hand=hand.replace("ss","s")
    for h in hand:
        if h=="p":
            score+=S
        elif h=="r":
            score+=P
        else:
            score+=R
print(score)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K=MI()
    R,S,P=MI()
    T=ST()
    te = [""]*N
    ans = 0
    win = {"r":"p","s":"r","p":"s"}
    for i,t in enumerate(T):
        if i>=K and win[t]==te[i-K]:
            continue
        else:
            if t=="r":
                ans += P
                te[i]="p"
            elif t=="s":
                ans += R
                te[i]="r"
            else:
                ans += S
                te[i]="s"
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
u = ""
for i in t:
    if len(u)<k:
        ans += a[i]
        u+=b[i]
    elif u[-k] == b[i]:
        u+="1"
        ans += 0
    else:
        ans += a[i]
        u += b[i]

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = [int(i) for i in input().split()]
    R, S, P = [int(i) for i in input().split()]
    T = input()
    hand = {"r":P, "s":R, "p":S}
    res = 0
    for i in range(K):
        # print(K)
        last = ""
        j = i
        while j < N:
            # print(j)
            aite = T[j]
            if aite != last:
                res += hand[aite]
                last = aite
            else:
                last=""
            j += K
    print(res)
main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
flag = [0]*N
ans = 0
for i in range(N):
    if i-K>=0 and T[i-K] == T[i] and flag[i-K]:
        continue
    if T[i] == 'r':
        ans+=P
    elif T[i] == 's':
        ans+=R
    else:
        ans+=S
    flag[i] = True
print(ans)

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())
    point = list(map(int, readline().split()))
    T = readline().strip()

    T = T.translate(str.maketrans('rsp', '012'))
    T = list(map(int, T))

    ans = 0
    for i in range(K):
        vec = T[i::K]
        M = len(vec)

        dp = [[0] * 3 for _ in range(M + 1)]
        for j in range(M):
            for k in range(3):
                dp[j + 1][k] = max(dp[j][(k + 1) % 3], dp[j][(k + 2) % 3])
                if (k + 1) % 3 == vec[j]:
                    dp[j + 1][k] += point[k]
        ans += max(dp[M])

    print(ans)
    returnimport sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())
    point = list(map(int, readline().split()))
    T = readline().strip()

    T = list(map(int, T.translate(str.maketrans('rsp', '012'))))

    hand = [0] * N
    ans = 0
    for i, h in enumerate(T):
        win = (h - 1) % 3
        if i >= K and win == hand[i - K]:
            hand[i] = -1
        else:
            hand[i] = win
            ans += point[win]

    print(ans)
    return


if __name__ == '__main__':
    main()



if __name__ == '__main__':
    main()

Submission status: Runtime Error

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])
            # じゃんけんで負けか引き分けたとき
            else;
                dp[v][w] = max(dp[v][w],dp[v-K][k])    
# K 個に分けた各グループの部分和の最大値の総和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
T = list(input()) 
T = [0 for _ in range(k)] + T
L = [0 for _ in range(k)]
ans = 0
for i in range(k,n+k):
    if T[i] == "r" and L[i-k] != "p":
        ans += p
        L.append("p")
    elif T[i] == "s" and L[i-k] != "r":
        ans += r
        L.append(r)
    elif T[i] == "p" and L[i-k] != "s":
        ans += s
        L.append(s)
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(n,k,r,s,p,t):
  winHand = {"r":"p", "s":"b", "p":"s"}
  bestHandMemo = [""]*(n+1) # i手目の勝ち手
  
  def calcPoint(char):
    if char == "r":
      return p
    elif char == "s":
      return r
    elif char == "p":
      return s
    else:
      raise ValueError
  def dp(i):
    if i == 0:
      return 0
    elif i <= k:
      bestHandMemo[i-1] = winHand[t[i-1]] # 自由に出せる
      return dp(i-1) + calcPoint(t[i-1])
    elif winHand[t[i-1]] == bestHandMemo[i-k-1]:
      bestHandMemo[i-1] = "" # あいこでも負けても同じこと
      return dp(i-1)
    else: # 勝てる
      bestHandMemo[i-1] = winHand[t[i-1]]
      return dp(i-1) + calcPoint(t[i-1])
  
  memo = [0]*(n+1)
  for i in range(n+1):
    memo[i] = dp(i)

  return memo[n]
    



def main():
  N,K = map(int,input().split())
  R,S,P = map(int,input().split())
  T = input()
  print(solve(N,K,R,S,P,T))
  return

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
from collections import Counter

#input
N,K = list(map(int,input().split()))
R,S,P = list(map(int,input().split()))

T = list(input())
T_ =T.copy()

# N=2*10**5
# T=[random.choice(['s', 'r', 'p']) for _ in range(N)]

check=set(['s', 'r', 'p'])

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

T_point = [0]*N
for n in range(N):
    T_point[n]=point[T[n]]
    
for k in range(K,N):
    check_out = set()
    if T[k] == T[k-K]: # K回前の手と同じ場合
        check_out.add(T[k])
        if k+K <= N:
            check_out.add(T[k+K])
            
        check_out=check-check_out
        
        T[k]=list(check_out)[0]
         
ans=0

for t in range(len(T)):
    if T[t] == T_[t]:
        ans += point[T[t]]
print(ans)

Submission status: Runtime Error

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, t in enumerate(T):
    if t == "r":
      c = "p"
      point = P
    elif t == "s":
      cc ="r" 
      point = R
    elif t == "p":
      c = "s"
      point = P
    
    if (i - K >= 0) and (command[i - K] == c):
        c = ""
        point = 0
    
    ans += point
    command.append(c)
print(ans)

Submission status: Runtime Error

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, t in enumerate(T):
    if t == "r":
      c = "p"
      point = P
    elif t == "s":
      cc ="r" 
      point = R
    elif t == "p":
      c = "s"
      point = P
    
    if (i - K >= 0) and (c[i - K] == c):
        c = ''
        point = 0
    
    ans += point
    command.append(c)
print(ans)

Submission status: Runtime Error

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, t in enumerate(T):
    if t == "r":
      command = "p"
      point = P
    elif t == "s":
      command ="r" 
      point = R
    elif t == "p":
      command = "s"
      point = P
    
    if (i - K >= 0) and (command[i - K] == command):
        command = ''
        point = 0
    
    ans += point
    command.append(command)
print(ans)

Submission status: Runtime Error

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, t in enumerate(T):
    if t == "r":
      command = "p"
      point = P
    elif t == "s":
      command ="r" 
      point = R
    elif t == "p":
      command = "s"
      point = P
    
    if (i - K > 0) and (command[i - K] == command):
        command = ''
        point = 0
    
    ans += point
    command.append(command)
print(ans)

Submission status: Runtime Error

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, t in enumerate(T):
    if t == "r":
      command = "p"
      point = P
    elif t == "s":
      command ="r" 
      point = R
    elif t == "p":
      command = "s"
      point = P
    
    if (i - K > 0) and (command[i - K] == command):
        command = ''
        point = 0
    
    ans += point
    command.append(command)

Submission status: Runtime Error

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
print(score)
#添字は0から始まることに注意
#r : 0 s : 1 p : 2


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

Submission status: Runtime Error

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"}
mm = []
ans = 0
print(score)
#添字は0から始まることに注意
#r : 0 s : 1 p : 2

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N, K = list(map(int, input().split()))
  R, S, P = list(map(int, input().split()))
  T = input()[:-1]

  mem = []
  hand_map = {'r': 'p', 's': 'r', 'p': 's'}
  score_map = {'r': P, 's': R, 'p': S}

  score = 0

  for i in range(K):
    mem.append(hand_map[T[i]])
    score += score_map[T[i]]

  for i in range(K, N):
    if not mem[i-K] == hand_map[T[i]]:
      mem.append(hand_map[T[i]])
      score += score_map[T[i]]
      continue
    cand = ['r', 's', 'p']
    # print(mem[i-K])
    cand.remove(mem[i-K])
    if i+K <= N and not(mem[i-K] == hand_map[T[i+K]]):
      cand.remove(hand_map[T[i+K]])
    mem.append(cand[0])

  print(score)


if(__name__ == '__main__'):
  main()

Submission status: Runtime Error

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

res = 0
prev = ''
for i, elem in enumerate(t):
  if i < k:
    if elem == 'r':
      res += p
      prev += 'p'
    elif elem == 's':
      res += r
      prev += 'r'
    else:
      res += s
      prev += 's'
  else:
    if elem == 'r':
      if prev[i-k] == 'p':
        if len(t) >= (i+k) and t[i+k] == 'r':
          prev += 's'
        else:
          prev += 'r'      
      else:
        res += p
        prev += 'p'
    elif elem == 's':
      if prev[i-k] == 'r':
        if len(t) >= (i+k) and t[i+k] == 's':
          prev += 'p'
        else:
          prev += 's'
      else:
        res += r
        prev += 'r'
    else:
      if prev[i-k] == 's':
        if len(t) >= (i+k) and t[i+k] == 'p':
          prev += 'r'
        else:
          prev += 'p'
      else:
        res += s
        prev += 's'
print(res)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
s,p,r=map(int,input().split())
f={'s':s,'p':p,'r':r}
t=str(input())
ans=0
for i in range(k):
  a=i+k
  last=t[i]
  ans+=f[last]
  while a<n-k:
    if t[a-k]==last:
      if t[a+k]==last:
        if last=='s':
          last='r'
        else:
          last='s'
      else:
        if last=='s':
          if t[a+k]=='r':
            last='p'
          else:
            last='r'
        elif last=='r':
          if t[a+k]=='s':
            last='p'
          else:
            last='s'
        else:
          if

Submission status: Runtime Error

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

win_point = {
    'r': r,
    's': s,
    'p': p,
}

next_hands = {
    'r': ['s', 'p'],
    's': ['r', 'p'],
    'p': ['r', 's'],
}

enemy_hands = input()


def can_win(enemy_hand, my_hands):
    # 勝てる場合にはTrueと勝てる手を教えてくれる
    if enemy_hand == 'r' and 'p' in my_hands:
        return True, 'p'
    if enemy_hand == 's' and 'r' in my_hands:
        return True, 'r'
    if enemy_hand == 'p' and 's' in my_hands:
        return True, 's'

    # 勝てる手がない場合
    return False, None


def choose_hand(enemy_hand, next_enemy_hand, now_hands):
    # 次の手に勝てるようにその手以外を選択する
    if next_enemy_hand == enemy_hand:
        # 次回も同じ手ならどっちでも良い
        return now_hands[0]

    win, hand = can_win(next_enemy_hand, enemy_hand)

    # 次の手と今の相手の手を戦わせる
    # 後の手が勝ったら今の手と同じものを出す
    # 今の手が勝ったら後の手と同じものと出す
    if win:
        return now_hands[enemy_hand]
    else:
        return now_hands[next_enemy_hand]


point = 0

for index in range(K):
    target = index
    now_hands = ['r', 'p', 's']
    for i in range(index, N, K):
        win, hand = can_win(enemy_hands[i], now_hands)

        if win:
            point += win_point[hand]
            now_hands = next_hands[hand]
        else:
            if i + K < N:
                next_enemy_hand = enemy_hands[i+K]
                now_hands = next_hands[choose_hand(
                    enemy_hands[i], next_enemy_hand, now_hands)]

print(point)

Submission status: Runtime Error

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

commands = [""]*n
ans = 0

for i, t in enumerate(T):
    if t == "p":
        point = s
    elif t == "s":
        point = r
    elif t == "r":
        point = p

    if(i - k) >= 0 and (commands[i-k] == command):
        point = 0

    ans += point
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
score = {'r': R, 's': S, 'p': P}
T = input()
hand = {'r': 'p', 's': 'r', 'p': 's'}

history = ['a'] * (2 * N)
cnt = 0
for i, t in enumerate(T):
    l = i - K
    r = i + K
    u = hand[t]
    flag = 1

    if u == history[l]:
        u = T[r]
        flag = 0

    cnt += score[u] * flag
    history[i] = u

print(cnt)

Submission status: Runtime Error

Solution code:
def f(c):
    """
    入力に対する勝ち手を出力
    """
    if c=="r":
        return "p"
    elif c=="s":
        return "r"
    else:
        return "s"

def main():
    """
    まずは全て勝つ組み合わせを作って、合計ポイントを求める。
    iを0からN-Kまで変化させ、T(i)=T(k+i)となる時、
    T(k+i)をT(i)、T(i+2K)と異なる手に変更する。
    ※T(i)を変更すると、T(i)=T(i+k)=T(i+2K)=...=と連続した時に、
    全て変更されてスコアが最大にならない。
    T(k+i)は勝ちから"あいこまたは負け"に変化するので、合計ポイントから差っ引く。
    """

    #input
    N,K=map(int,input().strip().split())
    R,S,P=map(int,input().strip().split())
    T=list(input())
    win_T=list(map(lambda x:f(x),T))
    point={"r":R,"s":S,"p":P}
    score=sum([point[win_T[n]] for n in range(N)])
    for i in range(N-K):
        l=["r","s","p"]
        if win_T[i]==win_T[i+K]:
            score-=point[win_T[i+K]]
            l.remove(win_T[i])
            if i<=N-2*K and win_T[i]!=win_T[i+2*K]:
                l.remove(win_T[i+2*K])
            win_T[i+K]=l[0]
    return score

if __name__=="__main__":
    print(main())

Submission status: Runtime Error

Solution code:
n.k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
    if t[i+k] == t[i]:
        t[i+k] == 0
x = t.count("r")*p+t.count("S")*r+t.count("p")*s
print(x)

Submission status: Runtime Error

Solution code:
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = list(input())
    score = {"r": p, "s": r, "p": s}
    answer = 0
    for i in range(n):
        if i < k:
            answer += score[t[i]]
            if t[i] == t[i + k]:
                t[i + k] = t[i + k] + "*"
        elif i + k < n:
            if "*" not in t[i]:
                answer += score[t[i][0]]
                if t[i] == t[i + k]:
                    t[i + k] = t[i + k] + "*"
        else:
            if "*" not in t[i]:
                answer += score[t[i][0]]
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = list(input())
    score = {"r": p, "s": r, "p": s}
    answer = 0
    for i in range(n):
        if i < k:
            answer += score[t[i]]
            if t[i] == t[i + k]:
                t[i + k] = t[i + k] + "*"
        elif i + k < n:
            if "*" not in t[i]:
                answer += score[t[i]]
                if t[i] == t[i + k]:
                    t[i + k] = t[i + k] + "*"
        else:
            if "*" not in t[i]:
                answer += score[t[i]]
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    if n % 2:
        print(0)
    else:
        n //= 2
        i = 5
        answer = 0
        while i <= n:
            answer += n // i
            i *= 5
        print(answer)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
,k = map(int,input().split())
R,S,P =map(int,input().split())
T = list(input())
value= {'r':P,'s':R,'p':S}
ans = 0
pre = ''
#k個ごとのグループで考える
for i in range(k):
    num = i
    while num<n:
        if pre == T[num]:#同じ手だったら負けかあいこ．つまり0点カウント
            pre = ''
        else:
            pre = T[num]
            ans += value[pre]
        num += k
print(ans)

Submission status: Runtime Error

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