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 = list(map(int, input().split()))
T = list(input())

result = [0] * N
for i,t in enumerate(T):
    if t == "r":
        result[i] = P
    elif t == "s":
        result[i] = R
    else:
        result[i] = S

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

Submission status: Wrong Answer

Solution code:
# D - Prediction and Restriction
def fight(i, win_t):
	global rsp
	global ans
	global track
	
	if past_t(i) != win_t:
		ans += rsp[win_t]
		track += win_t
	else:
		future_t_ = future_t(i)
	
		for t in rsp:
			if t != win_t and t != future_t_:
				track += t
				break


def past_t(count):
	# K回前の手が何だったか確認する
	global k
	global track
	
	try:
		return track[count-k]
	except:
		return ''
		

def future_t(count):
	global k
	global cpu_t

	try:
		cpu = cpu_t[count+k]
		
		if cpu == 'r':
			return 'p'
		elif cpu == 's':
			return 'r'
		else:
			return 's'
	except:
		return ''
			

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

rsp = dict()
rsp['r'] = r
rsp['s'] = s
rsp['p'] = p

cpu_t = input()
track = ''
i = 0
ans = 0

for cpu in cpu_t:
	if cpu == 's':
		fight(i, 'r')
	elif cpu == 'p':
		fight(i, 's')
	else:
		fight(i, 'p')
										
	i += 1

print(ans)
#print(track)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

t = []
for l in list(input()):
    if l=='r':
        t.append(p)
    if l=='s':
        t.append(r)
    if l=='p':
        t.append(s)

for i in range(k,n):
    if t[i-k]==t[i]:
        t[i]=0
print(sum(t))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = [p if l=='r' else r if l=='s' else s for l in list(input())]

for i in range(k,n):
    if t[i-k]==t[i]:
        t[i]=0
print(sum(t))

Submission status: Wrong Answer

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

for i in range(len(T)):
    if T[i] == 'r':
        lst.append(P)
    elif T[i] == 's':
        lst.append(R)
    else: # T[i] == 'p'
        lst.append(S)

for j in range(N):
    if j >= K and lst[j] == lst[j-K]:
        lst[j] = 0
print(sum(lst))

Submission status: Wrong Answer

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

for i in range(len(T)):
    if T[i] == 'r':
        lst.append(P)
    elif T[i] == 's':
        lst.append(R)
    else: # T[i] == 'p'
        lst.append(S)
#print(lst)

for j in range(N,K,-1):
    if lst[j-1] == lst[j-K-1]:
        lst[j-K-1] = 0

print(sum(lst))

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int,K:int,R:int,S:int,P:int,T:str) -> int:
   dic = {"r":R,"s":S,"p":P}
   dic2 = {"r":["p","r"],"s":["r","s"],"p":["s","p"]}
   total = 0
   ans = []
   for n in range(N):
      target = T[n]
      if(n  < K):
         ans.append(dic2[target][0])
         total += dic[dic2[target][0]]
      else:
         if(ans[n - K] == dic2[target][0]):
            ans.append(dic2[target][1])
         else:
            ans.append(dic2[target][0])
            total += dic[dic2[target][0]]
   return total

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   R,S,P = map(int,input().split())
   T = input()
   print(myAnswer(N,K,R,S,P,T))
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
S = input()
pt = []
for i in range(n):
    if S[i]=='r': t = p
    elif S[i]=='s': t = r
    else: t=s
    pt.append(t)
for i in range(n-k):
    if pt[i]==pt[i+k]:
        pt[i+k]=0
print(sum(pt))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
S = input()
pt = []
for i in range(n):
    if S[i]=='r': t = p
    elif S[i]=='s': t = r
    else: t=s
    pt.append(t)
for i in range(k,n):
    if pt[i]==pt[i-k]:
        pt[i]=0
print(sum(pt))

Submission status: Wrong Answer

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:
    if len(ha) == 0:
        continue

    dp=[janken(ha[0])]
    if len(ha) == 1:
        counter=dp[0]
        continue

    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: Wrong Answer

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
           
                

for i in range(k):
    st1_sub = st[i::k]
    st2_sub = st[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]
        if st2_sub[j+1] == st2_sub[j]:
            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: Wrong Answer

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')
     
st1 = st
for i in range(k):
    st1_sub = st1[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]
    st1[i::k] = st1_sub

for i in range(len(st)):
    if st1[i] != t[i]:
        if st1[i] == 'r' :
            score1 += r
        elif st1[i] == 's' :
            score1 += s
        elif st1[i] == 'p' :
            score1 += p
st2 = st
for i in range(k):
    st2_sub = st2[i::k]
    t_sub = t[i::k]
    
    for j in range(len(st2_sub)-2, -1, -1):
        if st2_sub[j+1] == st2_sub[j]:
            st2_sub[j] = t_sub[j]
    st2[i::k] = st2_sub

for i in range(len(st)):
    if st2[i] != t[i]:
        if st2[i] == 'r' :
            score2 += r
        elif st2[i] == 's' :
            score2 += s
        elif st2[i] == 'p' :
            score2 += p
 
score = max(score1, score2)
print(score)

Submission status: Wrong Answer

Solution code:

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

# t_sub = #sub string
ban = []
st = []
score = 0

for i in t:
    if i == 'r' :
        st.append('p')
    elif i == 's' :
        st.append('r')
    else:
        st.append('s')
     

for i in range(k):
    st_sub = st[i::k]
    t_sub = t[i::k]
    
    for j in range(len(st_sub)-1):
        if st_sub[j+1] == st_sub[j]:
            st_sub[j+1] = t_sub[j+1]
    st[i::k] = st_sub

for i in range(len(st)):
    if st[i] != t[i]:
        if st[i] == 'r' :
            score += r
        elif st[i] == 's' :
            score += s
        else:
            score += p
        
print(score)

Submission status: Wrong Answer

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

ans=[0]*N
i=0
while i<N:
    if i<K:
        if T[i]=='r':
            ans[i]=P
        elif T[i]=='s':
            ans[i]=R
        else:
            ans[i]=S
    else:
        if T[i]=='r':
            if T[i-K]=='r':
                ans[i]=0
            else:
                ans[i]=P
        elif T[i]=='s':
            if T[i-K]=='s':
                ans[i]=0
            else:
                ans[i]=R
        else:
            if T[i-K]=='p':
                ans[i]=0
            else:
                ans[i]=S
    i+=1

print(sum(ans))

Submission status: Wrong Answer

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

ans=[0]*N
i=0
while i<N:
    if i<K:
        if T[i]=='r':
            ans[i]=P
        elif T[i]=='s':
            ans[i]=R
        else:
            ans[i]=S
    else:
        if T[i]=='r':
            if ans[i-K]==P:
                ans[i]=0
            else:
                ans[i]=P
        elif T[i]=='s':
            if ans[i-K]==R:
                ans[i]=0
            else:
                ans[i]=R
        else:
            if ans[i-K]==S:
                ans[i]=0
            else:
                ans[i]=S
    i+=1

print(sum(ans))

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
R,S,P=map(int, input().split())
T=input()
hand=[0]*(len(T))
for i in range(len(T)):
    if i>K-1:
        if (T[i]=='r') and (hand[i-K]!=P):
            hand[i]=P
        elif (T[i]=='s') and (hand[i-K]!=R):
            hand[i]=R
        elif (T[i]=='p') and (hand[i-K]!=S):
            hand[i]=S
        else:
            hand[i]=0
    elif i<=K-1:
        if (T[i]=='r'):
            hand[i]=P
        elif (T[i]=='s'):
            hand[i]=R
        elif (T[i]=='p'):
            hand[i]=S
print(sum(hand))

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    RSP = list(map(int, input().split()))
    T = list(input().rsplit()[0])

    win_hand = ['s', 'p', 'r']
    ans = 0
    flag = True
    for i in range(N):
        for j in range(3):
            if T[i] == win_hand[j]:
                if i >= K:
                    if T[i] == T[i-K]:
                        if flag:
                            flag = False
                            continue
                        else:
                            flag = True
                        continue
                ans += RSP[j]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    RSP = list(map(int, input().split()))
    T = list(input().rsplit()[0])

    win_hand = ['s', 'p', 'r']

    ans = 0
    flag = True
    for i in range(N):
        for j in range(3):
            if T[i] == win_hand[j]:
                if i >= K:
                    if T[i] == T[i-K] and flag:
                        flag = False
                        continue
                ans += RSP[j]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    RSP = list(map(int, input().split()))
    T = list(input().rsplit()[0])

    win_hand = ['s', 'p', 'r']


    ans = 0
    for i in range(N):
        for j in range(3):
            if T[i] == win_hand[j]:
                if i >= K:
                    if T[i] == T[i-K]:
                        continue
                ans += RSP[j]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    RSP = list(map(int, input().split()))
    T = list(input().rsplit()[0])

    # new_rsp = [RSP[-2], RSP[0], RSP[1]]

    dp = [[0]*3 for i in range(N+1)]

    win_hand = ['s', 'p', 'r']
    can_hand = [[1, 2], [0, 2], [1, 2]]
    # # i回目の勝負で
    # for i in range(N):
    #     # jの手を出したときのフルスコア
    #     for j in range(3):
    #         if T[i] == win_hand[j]:
    #             score = RSP[j]
    #         else:
    #             score = 0

    #         if i < K:
    #             dp[i+1][j] = max(dp[i]) + score
    #         else:

    # print((dp))

    ans = 0
    hand = [0]*N
    for i in range(N):
        for j in range(3):
            if T[i] == win_hand[j]:
                if i > K:
                    if T[i] == T[i-K]:
                        continue
                ans += RSP[j]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
score_dic = {"r":R,"s":S,"p":P}
win_dic = {"r":"p","s":"r","p":"s"}
T = list(input())
score = 0
for i in range(0,N,1):
    if i >= K and T[i-K] == T[i]:
        T[i]="m"
        print(0)
    else:
        score+=score_dic[win_dic[T[i]]]
        print(score_dic[T[i]])

print(score)

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(input):
    [N, K] = string_to_int(input[0])
    [R, S, P] = string_to_int(input[1])
    T = input[2]

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

    point = 0
    history = []
    for i, hand in enumerate(T):
        prohibid_hand = history[i - K] if i >= K else None
        if prohibid_hand is None or prohibid_hand != best_hands[hand]:
            point += point_table[best_hands[hand]]
            history.append(best_hands[hand])
        else:
            history.append(hand)

    return point


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(3))
    print(ret)

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(input):
    [N, K] = string_to_int(input[0])
    [R, S, P] = string_to_int(input[1])
    T = input[2]

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

    point = 0
    history = []
    for i, hand in enumerate(T):
        if i < K or history[i - K] != best_hands[hand]:
            my_hand = best_hands[hand]
            point += point_table[my_hand]
        else:
            my_hand = hand
        history.append(my_hand)

    return point


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(3))
    print(ret)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
#rのときpの点、sのときｒ、ｐのときｓ

from collections import Counter

taka = ''
ans = 0


for te in t[:k]:
    if te == 'r':
        taka += 'p'
        ans += p
    elif te == 's':
        taka += 'r'
        ans += r
    else:
        taka += 's'
        ans += s

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


print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
R, S, P = MAP()
T = input()

t = []

for i in range(N):
	if T[i] == "r":
		t.append(P)
	if T[i] == "p":
		t.append(S)
	if T[i] == "s":
		t.append(R)

ans = sum(t)

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

print(ans)

Submission status: Wrong Answer

Solution code:
def point(x):
    y=x[0]
    point=y
    con=1
    
    for i in x[1:]:
        
        if i!=y:
            point+=i
            con=1
            
        elif i==y and con==1:
            con=0
            
        elif i==y and con==0:
            point+=i
            con=1
        
        y=i
        
    return point


n,k=map(int,input().split())

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

t=input()

list_point=[]

for i in t:
    if i=='r':
        list_point.append(p)
        
    elif i=='s':
        list_point.append(r)
        
    else:
        list_point.append(s)
        
points=0
    
for j in range(k):
    list_point2=[]
    for num,m in enumerate(list_point):
        if num%k==j:
            list_point2.append(m)
            
    plus=point(list_point2)
   
    points+=plus

print(points)

Submission status: Wrong Answer

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]:
            win[i] = t[i]
        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: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
scores = {'r': p, 's': r, 'p': s}
positions = {'r': [], 's': [], 'p': []}
for i in range(n):
    positions[t[i]].append(i)
total = 0
for key, value in positions.items():
    if len(value) <= 1:
        total += scores[key] * len(value)
    elif len(value) > 1:
        total += scores[key]
        for j in range(1, len(value)):
            if value[j] - value[j-1] == k:
                value[j] = n
                total += 0
            else:
                total += scores[key]
print(total)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())

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

T=list(input())
T=''.join(list(reversed(T)))


d={}
for j in range(N):
    if T[j]=='r':
        d[j]=p
    elif T[j]=='s':
        d[j]=r
    else:
        d[j]=s

for i in range(N):
    if i-K in d:
        if d[i]==d[i-K]:
            d[i]=0

score=0

for _,val in d.items():
    score+=val

print(score)

Submission status: Wrong Answer

Solution code:
import math

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

w = {"r": p, "s": r, "p": s}

li = [0 for _ in range(n)]
for i in range(len(t)):
    wp = w[t[i]]
    if not (i - k >= 0 and li[i - k] == wp):
        li[i] = wp

print(sum(li))

Submission status: Wrong Answer

Solution code:
import math

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

d = {"r": r, "s": s, "p": p}
li = [0 for _ in range(n)]


def win(h):
    wh = ""
    if h == "r":
        wh = "p"
    elif h == "s":
        wh = "r"
    elif h == "p":
        wh = "s"
    return wh


for i in range(k):
    li[i] = d[win(t[i])]

for i in range(k, n):
    li[i] = d[win(t[i])]
    if li[i - k] == li[i]:
        li[i] = 0

print(sum(li))

Submission status: Wrong Answer

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

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

picks = []
score = 0
for i in range(N):
    current = T[i]
    pick = winning[current]
    if i - K >= 0 and pick == picks[i-K]:
        pick = current
    else:
        score += scoredict[pick]
    picks.append(pick)

print(score)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S_, P = map(int, input().split())
T = input()
S = [[] for _ in range(K)]


def f(x):
    if x == "r":
        return P
    if x == "s":
        return R
    if x == "p":
        return S_


for i in range(K):
    S[i].append(T[i])
for i in range(N - K):
    S[i % K].append(T[i + K])
c = 0
t = ""
for i in range(len(S)):
    for j in range(len(S[i])):
        if t != S[i][j]:
            c += f(S[i][j])
        else:
            S[i][j] = ""
        t = S[i][j]
print(c)

Submission status: Wrong Answer

Solution code:
#　149D
n, k = map(int, input().split())
point={}
point['s'],point['p'],point['r'] = map(int, input().split())
s = input()

ans =0
before = [0]*k
for i in range(len(s)):
    if i > k:
        if (s[i] == s[i-k]) & (before[i%k]==1):
            before[i%k] = 0
        else:
            ans += point[s[i]]
            before[i%k] = 1
    else:
        ans += point[s[i]]
        before[i%k] = 1
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, t = open(0)
n, k = map(int, a.split())
r, s, p = map(int, b.split())
d = {"r": p, "s": r, "p": s}
l = [0]*n
for i, s in enumerate(list(t.strip())):
  c = d[s]
  if i-k >= 0 and l[i-k] == c:
    continue
  l[i] = c
print(sum(l))

Submission status: Wrong Answer

Solution code:
a, b, t = open(0)
n, k = map(int, a.split())
r, s, p = map(int, b.split())
d = {"r": p, "s": r, "p": s}
l = [0]*n
for i, s in enumerate(list(t.strip())):
  c = d[s]
  if l[i-k] != c:
    l[i] = c
print(sum(l))

Submission status: Wrong Answer

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

def score(t):
    if t == 'r':return p
    if t == 's':return r
    else:return s

dp = [[0 for i in range(2)] for j in range(n + 1)]
for i in range(k):
    dp[i][0] = 0
    dp[i][1] = score(t[i])
    tmp = 0
    j = i + k
    while j < n:
        dp[j][0] = max(dp[j - k])
        if t[j] == t[j - k]:
            dp[j][1] = dp[j - k][0] + score(t[j])
        else:
            dp[j][1] = max(dp[j - k]) + score(t[j])
        tmp = j
        j += k
    ans += max(dp[tmp])
print(ans)

Submission status: Wrong Answer

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

def score(t):
    if t == 'r':return p
    if t == 's':return r
    else:return s

dp = [[0 for i in range(2)] for j in range(n + 1)]
for i in range(k):
    dp[i][0] = 0
    dp[i][1] = score(t[i])
    tmp = 0
    for j in range(i + k,n,k):
        if t[j] == t[j - k]:
            dp[j][0] = max(dp[j - k])
            dp[j][1] = dp[j - k][0] + score(t[j])
        else:
            dp[j][0] = max(dp[j - k])
            dp[j][1] = max(dp[j - k]) + score(t[j])
        tmp = j
    ans += max(dp[tmp])
print(ans)

Submission status: Wrong Answer

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 = ''
x = ''
for i in range(last,k):
  for j in range(roop):
    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: Wrong Answer

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

ans = [0] * n
for i in range(n):
    if t[i] == 'r':
        ans[i] = p
        if i >= k and ans[i-k] == p:
            ans[i] = 0
    if t[i] == 's':
        ans[i] = r
        if i >= k and ans[i-k] == r:
            ans[i] = 0
    if t[i] == 'p':
        ans[i] = s
        if i >= k and ans[i-k] == s:
            ans[i] = 0

print(sum(ans))

Submission status: Wrong Answer

Solution code:
def main():
    n,k = list(map(int, input().split()))
    rsp = list(map(int, input().split()))
    j_machine = list(input())
    j_human = []
    score = 0
    for i, v in enumerate(j_machine):
        hand = ''
        points = 0
        hand, points = ret_win_hand_point(v, rsp)

        if i - k >= 0 and hand == j_human[i - k]:
            f_hand = [hand]
            if i + k < len(j_machine):
                h = ret_win_hand_point(j_machine[i + k], rsp)
                f_hand.append(h)
            for v in ['r','s','p']:
                if v not in f_hand:
                    hand = v
                    break
            points = 0
        score += points
        j_human.append(hand)
    print(score)


def ret_win_hand_point(machine, rsp):
    if machine == 'r':
        hand = 'p'
        points = rsp[2]
    elif machine == 'p':
        points = rsp[1]
        hand = 's'
    else:
        points = rsp[0]
        hand = 'r'
    return hand, points

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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