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: Runtime Error

Solution code:
n, k = map(int, input().split())
r, ss, p = map(int, input().split())
s = input()
hands = [None]*n
wins = {'r':'p', 's':'r', 'p':'s'}
h_s = {'r':r, 's':ss, 'p':p}
ans = 0
for i, c in enumerate(s):
    if i - k >= 0:
        if wins[c] == hands[i-k]:æ
            hs = set(wins.keys())
            hs.remove(wins[c])
            if i + k < n:
                if wins[s[i+k]] in hs:
                    hs.remove(wins[s[i+k]])
            hands[i] = hs.pop()
            continue
    hand = wins[c]
    hands[i] = hand
    ans += h_s[hand]

print(ans)

Submission status: Runtime Error

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

cir = defaultdict(list)
for i in range(k):
    cir[i] = t[i::k]


def solve(sq):
    # 初手
    x = sq[0]
    if x == "r":
        before, score = "r", p
    elif x == "s":
        before, score = "s", r
    else:
        before, score = "p", s
    cnt = 1

    # 前回と違う手なら問答無用で勝てる、前回と同じ手なら奇数回目に勝てる
    for x in sq[1:]:
        if before != x:
            if x == "r":
                score += p
            elif x == "s":
                score += r
            else:
                score += s
            before = x
            cnt = 1
        elif cnt % 2 == 1:
            cnt += 1
        else:
            if x == "r":
                score += p
            elif x == "s":
                score += r
            else:
                score += s
            cnt += 1
    return score


ans = []
for i in range(k):
    ans.append(solve(cir[i]))

print(sum(ans))

Submission status: Runtime Error

Solution code:
mport sys
from collections import defaultdict
sys.setrecursionlimit(10**8)

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

cir = defaultdict(list)
for i in range(k):
    cir[i] = t[i::k]


def solve(li, r, s, p):
    v = []

    def f(li, v):
        if len(li) == 0:
            return 0

        score = 0

        # グーを出す時
        if "r" not in v:
            x = "r"
            if li[0] == "s":
                score = max(score, f(li[1:], ["r"]) + r)
            else:
                score = max(score, f(li[1:], ["r"]))

        # チョキを出す時
        if "s" not in v:
            x = "s"
            if li[0] == "p":
                score = max(score, f(li[1:], ["s"]) + s)
            else:
                score = max(score, f(li[1:], ["s"]))

        # パーを出す時
        if "p" not in v:
            x = "p"
            if li[0] == "r":
                score = max(score, f(li[1:], ["p"]) + p)
            else:
                score = max(score, f(li[1:], ["p"]))

        return score
    return f(li, v)


ans = []
for i in range(k):
    ans.append(solve(cir[i], r, s, p))

print(sum(ans))

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(map(str, input().rstrip()))

cir = defaultdict(list)
for i in range(k):
    cir[i] = t[i::k]


def solve(li, r, s, p):
    v = []

    def f(li, v):
        if len(li) == 0:
            return 0

        score = 0

        # グーを出す時
        if "r" not in v:
            x = "r"
            if li[0] == "s":
                score = max(score, f(li[1:], ["r"]) + r)
            else:
                score = max(score, f(li[1:], ["r"]))

        # チョキを出す時
        if "s" not in v:
            x = "s"
            if li[0] == "p":
                score = max(score, f(li[1:], ["s"]) + s)
            else:
                score = max(score, f(li[1:], ["s"]))

        # パーを出す時
        if "p" not in v:
            x = "p"
            if li[0] == "r":
                score = max(score, f(li[1:], ["p"]) + p)
            else:
                score = max(score, f(li[1:], ["p"]))

        return score
    return f(li, v)


ans = []
for i in range(K):
    ans.append(solve(cir[i], R, S, P))

print(sum(ans))

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

cir = defaultdict(list)
for i in range(k):
    cir[i] = t[i::k]


def solve(li, r, s, p):
    v = []

    def f(li, v):
        if len(li) == 0:
            return 0

        score = 0

        # グーを出す時
        if "r" not in v:
            x = "r"
            if li[0] == "s":
                score = max(score, f(li[1:], ["r"]) + r)
            else:
                score = max(score, f(li[1:], ["r"]))

        # チョキを出す時
        if "s" not in v:
            x = "s"
            if li[0] == "p":
                score = max(score, f(li[1:], ["s"]) + s)
            else:
                score = max(score, f(li[1:], ["s"]))

        # パーを出す時
        if "p" not in v:
            x = "p"
            if li[0] == "r":
                score = max(score, f(li[1:], ["p"]) + p)
            else:
                score = max(score, f(li[1:], ["p"]))

        return score
    return f(li, v)


ans = []
for i in range(k):
    ans.append(solve(cir[i], r, s, p))

print(sum(ans))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque

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

cir = defaultdict(deque)
for i in range(k):
    cir[i] = t[i::k]


def solve(li, r, s, p):
    v = []

    def f(li, v):
        if len(li) == 0:
            return 0

        score = 0

        # グーを出す時
        if "r" not in v:
            x = "r"
            if li[0] == "s":
                score = max(score, f(li[1:], ["r"]) + r)
            else:
                score = max(score, f(li[1:], ["r"]))

        # チョキを出す時
        if "s" not in v:
            x = "s"
            if li[0] == "p":
                score = max(score, f(li[1:], ["s"]) + s)
            else:
                score = max(score, f(li[1:], ["s"]))

        # パーを出す時
        if "p" not in v:
            x = "p"
            if li[0] == "r":
                score = max(score, f(li[1:], ["p"]) + p)
            else:
                score = max(score, f(li[1:], ["p"]))

        return score
    return f(li, v)


ans = []
for i in range(k):
    if len(cir[i]) == 0:
        continue
    ans.append(solve(cir[i], r, s, p))

print(sum(ans))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque

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

cir = defaultdict(deque)
for i in range(k):
    cir[i] = t[i::k]


def solve(li, r, s, p):
    v = []

    def f(li, v):
        if len(li) == 0:
            return 0

        score = 0

        # グーを出す時
        if "r" not in v:
            x = "r"
            if li[0] == "s":
                score = max(score, f(li[1:], ["r"]) + r)
            else:
                score = max(score, f(li[1:], ["r"]))

        # チョキを出す時
        if "s" not in v:
            x = "s"
            if li[0] == "p":
                score = max(score, f(li[1:], ["s"]) + s)
            else:
                score = max(score, f(li[1:], ["s"]))

        # パーを出す時
        if "p" not in v:
            x = "p"
            if li[0] == "r":
                score = max(score, f(li[1:], ["p"]) + p)
            else:
                score = max(score, f(li[1:], ["p"]))

        return score
    return f(li, v)


ans = []
for i in range(k):
    ans.append(solve(cir[i], r, s, p))

print(sum(ans))

Submission status: Runtime Error

Solution code:
# d
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = np.array(list(input()))
point = 0
for i in range(k):
    if t[i] == 'r':
        point += p
    elif t[i] == 's':
        point += r
    else:
        point += s

for i in range(k, n):
    if t[i] != t[i-k]:
        if t[i] == 'r':
            point += p
        elif t[i] == 's':
            point += r
        else:
            point += s
    else:
        t[i] = ''

print(point)

Submission status: Runtime Error

Solution code:
# d
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = np.array(list(input()))
point = 0
for i in range(k):
    if t[i] == 'r':
        point += p
    elif t[i] == 's':
        point += r
    else:
        point += s

for i in range(k, n):
    if t[i] != t[i-k]:
        if t[i] == 'r':
            point += p
        elif t[i] == 's':
            point += r
        else:
            point += s
    else:
        t[i] = ""

print(point)

Submission status: Runtime Error

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

for i in range(k, len(t)):
    if t[i] != t[i-k]:
        if t[i] == "r":
            score += p
        elif t[i] == "s":
            score += r
        else:
            score += s
    else:
        t[i] = ""

print(score)

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
R, S, P = map(int,input().split())
U = input()
lis = [[] for _ in range(K)]
for k in range(N):
    lis[k%K].append(T[k])
point = 0
h = ''
a = False
b = False
c = False
for l in range(K):
    T = lis[l]
    for i in range(0, 1):
        if T[i] == 'r':
            point += P
            h += 'p'
        elif T[i] == 's':
            point += R
            h += 'r'
        elif T[i] == 'p':
            point += S
            h += 's'
    print(point)
    for j in range(1, N):
        if T[j] == 'r':
            if T[j] != T[j-K]:
                point += P
                h += 'p'
            else:
                if a:
                    point += P
                    h += 'P'
                else:
                    h += 'x'
                a = not a
        elif T[j] == 's':
            if T[j] != T[j-K]:
                point += R
                h += 'r'
            else:
                if b:
                    point += R
                    h += 'R'
                else:
                    h += 'x'
                b = not b
        elif T[j] == 'p':
            if T[j] != T[j-K]:
                point += S
                h += 's'
            else:
                if c:
                    point += S
                    h += 'S'
                else:
                    h += 'x'
                c = not c
        print(point)
print(point)
print(h)

Submission status: Runtime Error

Solution code:
import math
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
hand=[[] for _ in range(k)]
for i in range(len(t)):
    hand[i%k].append(t[i])

def janken(str):
    if str == "r":
        return p
    elif str == "s":
        return r
    else:
        return s

counter=0

for ha in hand:
    dp=[janken(ha[0])]
    if ha[0]==ha[1]:
        dp.append(dp[0])
    else:
        dp.append(janken(ha[0])+janken(ha[1]))
    
    for i in range(2,len(ha)):
        if ha[i-1] != ha[i]:
            dp.append(dp[i-1]+janken(ha[i]))
        elif ha[i] != ha[i-2]:
            dp.append(dp[i-1])
        elif dp[i-2] == dp[i-1]:
            dp.append(dp[i-1]+janken(ha[i]))
        else:
            dp.append(dp[i-1])
    counter += dp[-1]
            

print(counter)

Submission status: Runtime Error

Solution code:


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

# t_sub = #sub string
ban = []
st = []
score1 = 0
score2 = 0

for i in t:
    if i == 'r' :
        st.append('p')
    elif i == 's' :
        st.append('r')
    else:
        st.append('s')
            
def score(l, m):
    c = 0       
    for i in range(len(l)):
        if l[i] != m[i]:
            if l[i] == 'r' :
                c += r
            elif l[i] == 's' :
                c += s
            elif l[i] == 'p' :
                c += p
    return c
           
                
st1 = st
for i in range(k):
    st1_sub = st1[i::k]
    st2_sub = st2[i::k]
    t_sub = t[i::k]
    
    for j in range(len(st1_sub)-1):
        if st1_sub[j+1] == st1_sub[j]:
            st1_sub[j+1] = t_sub[j+1]
            st2_sub[j] = t_sub[j]
    if score(st1_sub, t_sub) > score(st2_sub, t_sub):
        st[i::k] = st1_sub
    else:
        st[i::k] = st2_sub

print(score(st,t))

Submission status: Runtime Error

Solution code:
def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()[:-1].decode()

    ans = 0
    result = [False] * n
    for i in range(n):
        if k <= i and t[i] == t[i - k] and result[i - k]:
            continue
        if t[i] == 'r':
            ans += p
        elif t[i] == 's':
            ans += r
        elif t[i] == 'p':
            ans += s
        result[i] = True

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T= input()
def score(x):
  if x == 'r':
    return P
  elif x == 's':
    return R
  elif x == 'p':
    return S
  else:
    return 0
s = 0
for t in range(len(T)-1):
  if T[t] == T[t+1]:
    T[t+1] = 'z'
  s += score(T[t])
print(s)

Submission status: Runtime Error

Solution code:
from sys import stdin
# import math
N, K = [int(x) for x in stdin.readline().rstrip().split()]
R, S, P = [int(x) for x in stdin.readline().rstrip().split()]
s = input()
ans = 0
d = {'r': P, 's': R, 'p': S}
# print(d)
temp = [0 for i in range(len(s))]
for i, v in enumerate(s):
    # print(i, v, temp)
    if i <= len(s)-K and temp[i] != 1:
        if d[s[i+K]] == d[s[i]]:
            ans += d[s[i]]
            temp[i+K] = 1
        else:
            ans += d[s[i]]
    else:
        if temp[i] != 1:
            ans += d[s[i]]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
l = list(input())
roop = n//k
last = n%k
count = 0
x = ''
for i in range(last):
  for j in range(roop+1):
    if l[i+k*j] == 'r' and x != 'P':
      count += p
      x = 'P'
    elif l[i+k*j] == 's' and x != 'R':
      count += r
      x = 'R'
    elif l[i+k*j] == 'p' and x != 'S':
      count += s
      x = 'S'
    else:
      x = ''
if last == 0:
  roop -=1
for i in range(last,k):
  for j in range(roop+1):
    if l[i+k*j] == 'r' and x != 'P':
      count += p
      x = 'P'
    elif l[i+k*j] == 's' and x != 'R':
      count += r
      x = 'R'
    elif l[i+k*j] == 'p' and x != 'S':
      count += s
      x = 'S'
    else:
      x = ''
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
r = [int(i) for i in input().split()]
t = list(input())
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: Runtime Error

Solution code:
import collections

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] == T[i+K]:
        T[i+K] = "a"

c = colelctions.Counter(T)

print(c["r"]*P + c["s"]*R + c["p"]*S)

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

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':
                if t[c+k] == 's':
                    d[c]='s'
                else:
                    d[c]='r'
            else:
                ans += p ; d[c]='p'
        elif i == 's': 
            if x == 'r':
               if t[c+k] == 'p':
                    d[c]='p'
               else:
                    d[c]='s'
            else:
                ans += r;d[c]='r'
        elif i == 'p': 
            if x == 's':
               if t[c+k] == 'r':
                    d[c]='r'
               else:
                    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: Runtime Error

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: Runtime Error

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
d = {'r':r, 's':s, 'p':p}
t = input()
def janken(x):
    if x == 'r':
        return 'p'
    elif x == 's':
        return 'r'
    else:
        return 's'
l = ['']*k
for i in range(n):
    l[i%k] += t[i]
ans = 0
for i in l:
    dp = d(i[0]) + ['-1']*(len(i)-1)
    ans += d[janken(i[0])]
    for j in range(1, len(i)):
        if i[j] != i[j-1]:
            ans += d[janken(i[j])]
            dp[j] = d(i[j])
        else:
            dp[j] = d(i[j])
print(ans)

Submission status: Runtime Error

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

rec=[]
ans=0

def win(hand):
    if hand=='r':
        return ['p',P]
    elif hand=='s':
        return ['r',R]
    else:
        return ['s',S]

def gap(hand):
    if hand=='r':
        return 's'
    elif hand=='s':
        return 'p'
    else:
        return 'r'


for i in range(N):
    win_hand=win(T[i])[0]
    win_point=win(T[i])[1]
    same_hand=T[i]
    if 0<=i<=K-1:
        rec.append(win_hand)
        ans+=win_point
    else:
        if win_hand!=rec[i-K]:
            rec.append(win_hand)
            ans+=win_point
        else:
            if N-K<i<=N-1:
                rec.append(same_hand)#不要
            else:
                next_win_hand=win(T[i+K])[0]
                rec.append(gap(next_win_hand))

    #print(ans)

#print(rec)
print(ans)

Submission status: Runtime Error

Solution code:
# 初期入力
N,K = (int(x) for x in input().split(" "))
R,S,P = (int(x) for x in input().split(" "))
ten_janken_dic ={"R":R,"S":S,"P":P} #じゃんけんの役ごとの点を辞書
ten_janken_sort =sorted(ten_janken_dic.items(),key=lambda x: x[1])
T =input()

#合計点と高橋君が出す手を同時進行
sum_janken = 0 # 合計点
takahasi = [] # 高橋君が出す手,K回前の手も出せる＝すべて勝つとした場合
for i in T:
    if i =="r":
        sum_janken += P #6
        takahasi.append("P")
    elif i == "s":
        sum_janken += R #8
        takahasi.append("R")

    elif i == "p":
        sum_janken += S #7
        takahasi.append("S")
takahasi_mae =[]
from copy import deepcopy
takahasi_mae = deepcopy(takahasi)

# K回前の手は出せない        
for i,v in enumerate(takahasi[K:]):
    if v ==takahasi[(i+K)-K]:
        sum_janken -= ten_janken_dic[v]
        x = ["R","S","P"]
        if takahasi[(i+K)-K] in x:
            x.remove( takahasi[(i+K)-K] ) #K回前の手を消す
        if i+K+K <=len(takahasi):    
            if takahasi[i+K+K] in x:
                x.remove( takahasi[i+K+K] ) #K回後の手を消す
        if len(x) ==1:
            takahasi[i+K] =x[0]
        elif x[0]==ten_janken_sort[2][0] or x[1] ==ten_janken_sort[2][0] : #高い点を選ぶ
            takahasi[i+K] =ten_janken_sort[2][0]
        else:
            takahasi[i+K] =ten_janken_sort[1][0] #2番目に高い点のキー（点順でソートしてある）
print(sum_janken)

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[k+i] == t[i]:
        t[k+i] = 0
xs = t.count('r')*p+ t.count('s')*r+t.count('p')*s
print(x)

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[k+a] == t[a]:
        t[k+a] = 0
xs = t.count('r')*p+ t.count('s')*r+t.count('p')*s
print(x)

Submission status: Runtime Error

Solution code:
import numpy as np

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

points = {'r':{'s':r, 'r':0, 'p':0}, 's':{'s':0, 'r':0, 'p':s}, 'p':{'s':0, 'r':p, 'p':0}}
dp_dict = {'r':0, 's':1, 'p':2}
answer = 0
for i in range(k):
    sub_t = t[i::k]
    dp = np.zeros((len(sub_t)+1, 3))
    dp = np.array(dp, int)
    for k, s in enumerate(sub_t):
        for j in ['r', 's', 'p']:
            q = ['r', 's', 'p']
            q.remove(j)
            dp[k+1, dp_dict[j]] = max(dp[k, dp_dict[q[0]]], dp[k, dp_dict[q[1]]]) + points[j][sub_t[k]]
    answer += np.max(dp)
print(answer)

Submission status: Runtime Error

Solution code:
import sys

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

win_choice = {'s':'r', 'p':'s', 'r':'p'}
janken_point = {'r':r, 's':s, 'p':p}

dp = []
# a: 相手の手, x:自分が出せない手
def point(a, x=None):
    if x == win_choice[a]: return 0
    else: return janken_point[win_choice[a]]

def total_score(i, cnt, x=None):
    if cnt == 0:
        return 0
    else:
        a = t[(cnt - 1) * k + i]
        a_next = t[(cnt - 2) * k + i] if cnt > 1 else None
        choice = win_choice[a]
        if a == a_next and point(a, x) != 0:
            return point(a, x) + total_score(i, cnt - 1, choice)
        else:
            return point(a, x) + total_score(i, cnt - 1)

sys.setrecursionlimit(n + 1)
r = [0] * k
for i in range(n):
    i = i % k
    r[i] += 1

score = 0
for i in range(k):
    cnt = r[i]
    score += total_score(i, cnt)

print(score)

Submission status: Runtime Error

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

win_choice = {'s':'r', 'p':'s', 'r':'p'}
janken_point = {'r':r, 's':s, 'p':p}

# a: 相手の手, x:自分が出せない手
def point(a, x=None):
    if x == win_choice[a]: return 0
    else: return janken_point[win_choice[a]]

def total_score(i, cnt, x=None):
    if cnt == 0:
        return 0
    else:
        a = t[(cnt - 1) * k + i]
        choice = win_choice[a]
        return max(point(a, x) + total_score(i, cnt - 1, choice), total_score(i, cnt - 1))

r = [0] * k
for i in range(n):
    i = i % k
    r[i] += 1

score = 0
for i in range(k):
    cnt = r[i]
    score += total_score(i, cnt)

print(score)

Submission status: Runtime Error

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

dp=[0]*n
a = {"r":p, "s":r, "p":s}

for i in range(n):
    if i>=k and t[i]==t[i-k]: # どうせ得点できないので、次に影響しないように'x'
        dp[i]=0
        t[i]='x'
    else:
        dp[i]=d[t[i]]   
print(sum(dp))

Submission status: Runtime Error

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

for i in range(n-k):
  if t[i] == t[i+k]:
    t[i+k] = 0
print(sum(t.count("r")*r + t.count("s")*s + t.count("p")*p))

Submission status: Runtime Error

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

ans = 0

a = -(-N//K)
r = N%K
T2 = T + 'x'*r

li = []
for i in range(K):
    st = ''
    for j in range(a):
        c = T2[j*K + i]
        if st == '':
            st += c
        elif st[0] == c:
            st += c
        else:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S
            st = c
        if j == a-1:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S

print(ans)