Problem:


Score : 400 points

Problem Statement

At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)

Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):

R points for winning with Rock;

S points for winning with Scissors;

P points for winning with Paper.

However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string T. If the i-th character of T (1 \leq i \leq N) is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

if both players play the same hand, it is a draw.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

1 \leq R,S,P \leq 10^4

N,K,R,S, and P are all integers.

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.
We cannot earn more points, so the answer is 27.

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996



Sample input:
5 2
8 7 6
rsrpr


Sample output:
27

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()
ans = 0
hand = []
for i in t:
    if i == "r":
        hand.append("p")
    if i == "s":
        hand.append("r")
    if i == "p":
        hand.append("s")
for i, h in enumerate(t):
    if i >= k:
        if h == "r":
            if hand[i-k] != "p":
                ans += P
            else:
                hand[i] = "r"
        if h == "s":
            if hand[i-k] != "r":
                ans += R
            else:
                hand[i] = "s"
        if h == "p":
            if hand[i-k] != "s":
                ans += S
            else:
                hand[i] = "p"
    else:
        if h == "r":
            ans += P
        if h == "s":
            ans += R
        if h == "p":
            ans += S
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import itertools
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))






n,k=input2()
r,s,p=input2()
t=str(input())


ans_list=[]
b_k=0
ans=0
for i,hand in enumerate(t):
	if len(ans_list)>=k:
		b_k=ans_list[-k]

	if hand=="r":
		if  b_k==p:
			ans_list.append(r)
		else:
			ans_list.append(p)
			ans+=p
	elif hand=="s":
		if b_k==r:
			ans_list.append(s)
		else:
			ans_list.append(r)
			ans+=r
	elif hand=="p":
		if b_k==s:
			ans_list.append(p)
		else:
			ans_list.append(s)
			ans+=s



print(ans)











# 逆ポーランド記法
# ８クイーン
# 単純換字暗号

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import itertools
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))






n,k=input2()
r,s,p=input2()
t=str(input())


ans_list=[]
b_k=0
flag=False
for i,hand in enumerate(t):
	if len(ans_list)>=k:
		b_k=ans_list[-k]

	if hand=="r":
		if  b_k==p:
			ans_list.append(0)
		else:
			ans_list.append(p)
	elif hand=="s":
		if b_k==r:
			ans_list.append(0)
		else:
			ans_list.append(r)
	elif hand=="p":
		if b_k==s:
			ans_list.append(0)
		else:
			ans_list.append(s)



print(sum(ans_list))











# 逆ポーランド記法
# ８クイーン
# 単純換字暗号

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import itertools
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))






n,k=input2()
r,s,p=input2()
t=str(input())


ans_list=[]
b_k=0
flag=False
for i,hand in enumerate(t):
	if len(ans_list)>=k:
		b_k=ans_list[-k]

	if hand=="r":
		if  b_k==p:
			ans_list.append(0)
		else:
			ans_list.append(p)
	elif hand=="s":
		if b_k==r:
			ans_list.append(0)
		else:
			ans_list.append(r)
	elif hand=="p":
		if b_k==s:
			ans_list.append(0)
		else:
			ans_list.append(s)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
l=[]
ans=0
for i in range(N):
    if len(l)<K:
        if T[i]=="r":
            l.append("p")
            ans+=P
        elif T[i]=="s":
            l.append("r")
            ans+=R
        else:
            l.append("S")
            ans+=S
    elif l[-K]=="p" and T[i]=="r":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
        ans+=0
    elif l[-K]=="r" and T[i]=="s":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
        ans+=0
    elif l[-K]=="s" and T[i]=="p":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
        ans+=0
    else:
        if T[i]=="r":
            l.append("p")
            ans+=P
        elif T[i]=="s":
            l.append("r")
            ans+=R
        else:
            l.append("s")
            ans+=S

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
l=[]
ans=0
for i in range(N):
    if len(l)<K:
        if T[i]=="r":
            l.append("p")
            ans+=P
        elif T[i]=="s":
            l.append("r")
            ans+=R
        else:
            l.append("S")
            ans+=S
    elif l[-K]=="p":#len(l)>=Kのとき
        l.append("0")#適当な文字入れる
    elif l[-K]=="r":
        l.append("0")#適当な文字入れる
    elif l[-K]=="s":
        l.append("0")#適当な文字入れる
    else:
        if T[i]=="r":
            l.append("p")
            ans+=P
        elif T[i]=="s":
            l.append("r")
            ans+=R
        else:
            l.append("s")
            ans+=S

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
l=[]
ans=0
for i in range(N):
    if len(l)<K:
        if T[i]=="r":
            l.append("p")
            ans+=P
        elif T[i]=="s":
            l.append("r")
            ans+=R
        else:
            l.append("S")
            ans+=S
    elif l[-K]=="p" and T[i]=="r":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
    elif l[-K]=="r" and T[i]=="s":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
    elif l[-K]=="s" and T[i]=="p":#len(l)>=Kのとき、後ろからK番目がT[i]と同じとき
        l.append("0")#適当な文字入れる
    else:
        if T[i]=="r":
            l.append("p")
            ans+=P
        elif T[i]=="s":
            l.append("r")
            ans+=R
        else:
            l.append("s")
            ans+=S

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int,input().split())
T = input()
ans = 0
jr = [0]*N
js = [0]*N
jp = [0]*N
if T[0] == 'r':
  ans += R
  jr[0] = 1
elif T[0] =='s':
  ans += S
  js[0] = 1
else:
  ans += P
  jp[0] = 1
for i in range(1,N):
  if i < K:
    if T[i] == 'r':
      jr[i] = 1
      ans += R
    elif T[i] == 's':
      js[i] = 1
      ans += S
    else:
      jp[i] = 1
      ans += P
      
  elif i + K < N:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
    
    elif T[i] == 'p':
      if jp[i-K] == 0:
        jp[i] = 1
        ans += P
  else:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
        
    elif T[i] == 'p':
      if jp[i-K] == 0:
        jp[i] = 1
        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()
ans = 0
jr = [0]*N
js = [0]*N
jp = [0]*N
if T[0] == 'r':
  ans += R
  jr[0] = 1
elif T[0] =='s':
  ans += S
  js[0] = 1
else:
  ans += P
  jp[0] = 1
for i in range(1,N):
  if i < K:
    if T[i] == 'r':
      jr[i] = 1
      ans += R
    elif T[i] == 's':
      js[i] = 1
      ans += S
    else:
      jp[i] = 1
      ans += P
      
  elif i + K < N:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
    
    elif T[i] == 'p':
      if jp[i-K] == 0:
        jp[i] = 1
        ans += P
  else:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
        
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
        
    elif T[i] == 'p':
      if jp[i-K] == 1:
        jp[i] = 1
        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()
ans = 0
jr = [0]*N
js = [0]*N
jp = [0]*N
if T[0] == 'r':
  ans += R
  jr[0] = 1
elif T[0] =='s':
  ans += S
  js[0] = 1
else:
  ans += P
  jp[0] = 1
for i in range(1,N):
  if i < K:
    if T[i] == 'r':
      jr[i] = 1
      ans += R
    elif T[i] == 's':
      js[i] = 1
      ans += S
    else:
      jp[i] = 1
      ans += P
      
  elif i + K < N:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
      else:
        if T[i + K] == 'p':
          js[i] = 1
        else:
          jp[i] = 1
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
      else:
        if T[i+K] == 'r':
          jp[i] = 1
        else:
          jr[i] = 1
    elif T[i] == 'p':
      if jp[i-K] == 1:
        jp[i] = 1
        ans += P
      else:
        if T[i + K] == 's':
          jr[i] = 1
        else:
          js[i] = 1
  else:
    if T[i] == 'r':
      if jr[i-K] == 0:
        jr[i] = 1
        ans += R
    elif T[i] == 's':
      if js[i-K] == 0:
        js[i] = 1
        ans += S
    elif T[i] == 'p':
      if jp[i-K] == 1:
        jp[i] = 1
        ans += P
        
        
print(ans)

Submission status: Wrong Answer

Solution code:

battle_times, restriction = [int(n) for n in input().rstrip().split()]

win_points = [int(n) for n in input().rstrip().split()]
#r,s,p
win_points_dict = {'r':win_points[0], 's':win_points[1], 'p':win_points[2]}

opp_hand_patterns = input().rstrip()
my_hand_patterns = [0]*battle_times
total = 0

for i in range(battle_times):
    if my_hand_patterns[i]==0:

        if i<restriction:
            if opp_hand_patterns[i]=='r':
                my_hand_patterns[i]='p'
            elif opp_hand_patterns[i]=='s':
                my_hand_patterns[i]='r'
            else:
                my_hand_patterns[i]='s'
            
            total+=win_points_dict[my_hand_patterns[i]]

        elif i>=(battle_times-restriction):
            if opp_hand_patterns[i]=='r':
                if my_hand_patterns[i-restriction]=='p':
                    my_hand_patterns[i]='s'
                else:
                    my_hand_patterns[i]='p'
                    total+=win_points_dict[my_hand_patterns[i]]

            elif opp_hand_patterns[i]=='s':
                if my_hand_patterns[i-restriction]=='r':
                    my_hand_patterns[i]='p'
                else:
                    my_hand_patterns[i]='r'
                    total+=win_points_dict[my_hand_patterns[i]]

            else:#'p'
                if my_hand_patterns[i-restriction]=='s':
                    my_hand_patterns[i]='r'
                else:
                    my_hand_patterns[i]='s'
                    total+=win_points_dict[my_hand_patterns[i]]
            

        else:
            if opp_hand_patterns[i-restriction]==opp_hand_patterns[i]!=opp_hand_patterns[i+restriction]:
                # x,x,yの形
                if  (opp_hand_patterns[i-restriction]=='r' and my_hand_patterns[i-restriction]!='p') or \
                    (opp_hand_patterns[i-restriction]=='s' and my_hand_patterns[i-restriction]!='r') or \
                    (opp_hand_patterns[i-restriction]=='p' and my_hand_patterns[i-restriction]!='s'):
                    # i-restriction　番目で勝っていない
                        if opp_hand_patterns[i]=='r':
                            if my_hand_patterns[i-restriction]=='p':
                                my_hand_patterns[i]='s'
                            else:
                                my_hand_patterns[i]='p'
                                total+=win_points_dict[my_hand_patterns[i]]

                        elif opp_hand_patterns[i]=='s':
                            if my_hand_patterns[i-restriction]=='r':
                                my_hand_patterns[i]='p'
                            else:
                                my_hand_patterns[i]='r'
                                total+=win_points_dict[my_hand_patterns[i]]
                        
                        else:#p
                            if my_hand_patterns[i-restriction]=='s':
                                my_hand_patterns[i]='r'
                            else:
                                my_hand_patterns[i]='s'
                                total+=win_points_dict[my_hand_patterns[i]]

                else:# i-restriction　番目で勝った
                    if opp_hand_patterns[i+restriction]=='r':
                        my_hand_patterns[i+restriction]='p'
                        total+=win_points_dict[my_hand_patterns[i+restriction]]
                        if opp_hand_patterns[i]=='s':#ssr
                            my_hand_patterns[i]='s'
                        else:#ppr
                            my_hand_patterns[i]='r'
                            total+=win_points_dict[my_hand_patterns[i]]
                    
                    elif opp_hand_patterns[i+restriction]=='s':
                        my_hand_patterns[i+restriction]='r'
                        total+=win_points_dict[my_hand_patterns[i+restriction]]
                        if opp_hand_patterns[i]=='p':#pps
                            my_hand_patterns[i]='p'
                        else:#rrs
                            my_hand_patterns[i]='s'
                            total+=win_points_dict[my_hand_patterns[i]]
                    
                    else:#opp_hand_patterns[i+restriction]=='p'
                        my_hand_patterns[i+restriction]='s'
                        total+=win_points_dict[my_hand_patterns[i+restriction]]
                        if opp_hand_patterns[i]=='s':#ssp
                            my_hand_patterns[i]='p'
                        else:#rrp
                            my_hand_patterns[i]='r'
                            total+=win_points_dict[my_hand_patterns[i]]
            
            else:#other pattern
                if opp_hand_patterns[i]=='r':
                    if my_hand_patterns[i-restriction]=='p':
                        my_hand_patterns[i]='s'
                    else:
                        my_hand_patterns[i]='p'
                        total+=win_points_dict[my_hand_patterns[i]]

                elif opp_hand_patterns[i]=='s':
                    if my_hand_patterns[i-restriction]=='r':
                        my_hand_patterns[i]='p'
                    else:
                        my_hand_patterns[i]='r'
                        total+=win_points_dict[my_hand_patterns[i]]
                
                else:#p
                    if my_hand_patterns[i-restriction]=='s':
                        my_hand_patterns[i]='r'
                    else:
                        my_hand_patterns[i]='s'
                        total+=win_points_dict[my_hand_patterns[i]]


    else:#すでに決定されている
        continue


print(total)

Submission status: Wrong Answer

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

print(ans)
# r:グー, s:チョキ, p:パー

Submission status: Wrong Answer

Solution code:
n, k = (int(x) for x in input().split())
r, s, p = (int(x) for x in input().split())
t_ch = input()
t=[]
for i in range(n):
    t.append(t_ch[i])


for i in range(k-1, n):
    if t[i] == t[i-k]:
        t[i]=0
for i in range(0,n):
    if t[i]=="r":
        t[i]=p
    elif t[i]=="p":
        t[i]=s
    elif t[i]=="s":
        t[i]=r
print(sum(t))

Submission status: Wrong Answer

Solution code:
n, k = (int(x) for x in input().split())
r, s, p = (int(x) for x in input().split())
t_ch = input()
t=[]
for i in range(n):
    t.append(t_ch[i])


for i in range(k-1, n):
    if t[i] == t[i-k]:
        t[i]=0
print(t)
for i in range(0,n):
    if t[i]=="r":
        t[i]=p
    elif t[i]=="p":
        t[i]=s
    elif t[i]=="s":
        t[i]=r
print(sum(t))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

rec=[]
ans=0

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



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:
            rec.append(same_hand)
    #print(ans)

#print(rec)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
wins = {'r': 'p', 's': 'r', 'p': 's'}
aiko = {'r': 's', 's': 'p', 'p': 'r'}
points = {'r': r, 's': s, 'p': p}
outs = {'r': [], 's': [], 'p': []}

win_hands = []
for i, hand in enumerate(t):
  win_hands.append(wins[hand])

win_hands_copy = win_hands[:]
ans = []
for i, hand in enumerate(win_hands_copy):
  if i - k > -1 and i - k < len(t) and len(ans)>0:
    if win_hands[i-k] == hand:
      win_hands[i] = aiko[hand]
      continue
  ans.append(points[hand])
  
print(sum(ans))

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]
    R, S, P= [int(item) for item in input().split()]
    T = input()
    path_num = min(K, N-K)
    memo = [1 for _ in range(path_num)]
    def point_chk(s):
        if s == 'r':
            return P
        elif s == 's':
            return R
        elif s == 'p':
            return S
        else:
            raise

    
    max_point = 0
    for i, s in enumerate(T):
        if i < K:
            max_point += point_chk(s)
            memo[i%path_num] = s
        else:
            if s == memo[i%K]:
                memo[i%K] = 1
            else:
                memo[i%K] = s
                max_point += point_chk(s)
        # print(i, s, memo, max_point)
    
    print(max_point)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
# D - Prediction and Restriction

n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = list(str(input()))
A = []
ans = 0

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

for i in range(len(A)):
    if i<k:
        ans += A[i]
        continue

    if A[i]==A[i-k]:
        A[i] = 0
    else:
        ans += A[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
cnt = 0
flag = True
def jannkenn(string):
    if string ==  'r':
        return p
    elif string == 'p':
        return s
    elif string == 's':
        return r
for i in range(k):
    last = i
    for j in range(n):
        if i+k*j < n:
            if  last == i:
                cnt += jannkenn(t[i+k*j])
            elif t[last] != t[i+k*j]:
                cnt += jannkenn(t[i+k*j])
                
        else:
            break
        last = i+k*j
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from heapq import heapify, heappush, heappop, heappushpop, heapreplace

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = [r if i == 's' else s if i == 'p' else p for i in list(input())]
ans = 0
for i in range(k):
    j = i
    prev = False
    while j < n:
        if prev and t[j] == t[j-k]:
            prev = False
        else:
            ans += t[j]
            prev = True
        j += k
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from heapq import heapify, heappush, heappop, heappushpop, heapreplace

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = [r if i == 's' else s if i == 'p' else p for i in list(input())]
ans = 0
for i in range(k):
    j = i
    prev = False
    while j < n:
        if prev == False or t[j] != t[j-k]:
            prev = True
            ans += t[j]
        else:
            prev = False
        j += k
print(ans)

Submission status: Wrong Answer

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

score=0
scorei=0
myans=[]
myansi=""
for i in range(n):
    if(t[i]=="r"):
        myansi="p"
        scorei=p
    elif(t[i]=="s"):
        myansi="r"
        scorei=r
    else:
        myansi="s"
        scorei=s

    if(i>=k and myansi==myans[i-k]):
        myansi=t[i]
        scorei=0

    myans.append(myansi)
    score+=scorei
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()
G =  []
for i in range(K):
  G.append([])
for i in range(len(T)):
  G[i % K].append(T[i])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
string=list(input())
res=[0]*n
for i in range(len(string)):
    if i-k>=0:
        if string[i]=='r' and res[i-k]!=p:
            res[i]=p
        elif string[i]=='s' and res[i-k]!=r:
            res[i]=r
        elif string[i]=='p' and res[i-k]!=s:
            res[i]=s
    else:
        if string[i]=='r':
            res[i]=p
        elif string[i]=='s':
            res[i]=r
        elif string[i]=='p':
            res[i]=s
print(sum(res))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
chk = []
bad = ''
win = {
    'r': 'p',
    's': 'r',
    'p': 's'
}
lose = {
    'r': 's',
    's': 'p',
    'p': 'r'
}
same = {
    'r': 'r',
    's': 's',
    'p': 'p'
}
mat = {
    'r': R,
    's': S,
    'p': P
}
for i, t in enumerate(T):
    if i >= K:
        if win[t] == chk[i-K]:
            if t == chk[i-K]:
                chk.append(lose[t])
            else:
                chk.append(t)
        else:
            chk.append(win[t])
    else:
        chk.append(win[t])
ans = 0
for i in range(N):
    if win[T[i]] == chk[i]:
        ans += mat[chk[i]]
print(ans)

Submission status: Wrong Answer

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

a=0
b=0
c=0

if K>N:
  for i in range(N):
    if T[i]=="r":
      c+=1
    if T[i]=="s":
      a+=1
    if T[i]=="p":
      b+=1
  print(a*R+b*S+c*P)
else: 
  for i in range(K):
    if T[i]=="r":
      c+=1
    if T[i]=="s":
      a+=1
    if T[i]=="p":
      b+=1
  print(a,b,c)
  for j in range(K,N):
    if T[j]=="r":
      if T[j-K]=="r":
        c+=1
      if T[j-K]=="s":
        c+=1
      if T[j-K]=="p":
        pass
    if T[j]=="s":
      if T[j-K]=="r":
        pass
      if T[j-K]=="s":
        a+=1
      if T[j-K]=="p":
        a+=1
    if T[j]=="p":
      if T[j-K]=="r":
        b+=1
      if T[j-K]=="s":
        pass
      if T[j-K]=="p":
        b+=1
  print(a,b,c)
  print(a*R+b*S+c*P)

Submission status: Wrong Answer

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

def get_score(c):
    if c == 's':
        score = r
    elif c == 'p':
        score = s
    else:
        score = p
    return score

for i in range(n):
    c = t[i]
    if i < k:
        ans += get_score(c)
    else:
        if c == t[i-k]:
            if c != t[i-2*k]:
                ans += get_score(c)
        else:
            ans += get_score(c)

print(ans)

Submission status: Wrong Answer

Solution code:
nk=input().rstrip().split(" ")
rsp=input().rstrip().split(" ")
t=input()
n=int(nk[0])
k=int(nk[1])
r=int(rsp[0])
s=int(rsp[1])
p=int(rsp[2])
point=0
sta="neutral"

def read(l):
    global point
    global sta
    if sta=="rpointed":
        if l=="r":
            point+=0
            sta="rskiped"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=s
            sta="ppointed"
    elif sta=="spointed":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=0
            sta="sskiped"
        elif l=="p":
            point+=s
            sta="ppointed"
    elif sta=="ppointed":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=0
            sta="pskiped"
    elif sta=="rskiped" or sta=="sskiped" or sta=="pskiped":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=s
            sta="ppointed"
    elif sta=="neutral":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=s
            sta="ppointed"        
            
strs=[[] for i in range(k)]
for i in range(n):
    u=t[i:i+1]
    strs[i%k].append(u)
#print(strs)

for i in range(k):
    for j in range(len(strs[i])):
        read(strs[i][j])
        #print(sta)
        #print(point)
print(point)

Submission status: Wrong Answer

Solution code:
nk=input().rstrip().split(" ")
rsp=input().rstrip().split(" ")
t=input()
n=int(nk[0])
k=int(nk[1])
r=int(rsp[0])
s=int(rsp[1])
p=int(rsp[2])
point=0
sta="sskiped"

def read(l):
    global point
    global sta
    if sta=="rpointed":
        if l=="r":
            point+=0
            sta="rskiped"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=s
            sta="ppointed"
    elif sta=="spointed":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=0
            sta="sskiped"
        elif l=="p":
            point+=s
            sta="ppointed"
    elif sta=="ppointed":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=0
            sta="pskiped"
    elif sta=="rskiped" or sta=="sskiped" or sta=="pskiped":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=s
            sta="ppointed"
            
strs=[[] for i in range(k)]
for i in range(n):
    u=t[i:i+1]
    strs[i%k].append(u)
#print(strs)

for i in range(k):
    for j in range(len(strs[i])):
        read(strs[i][j])
        #print(sta)
        #print(point)
print(point)

Submission status: Wrong Answer

Solution code:
nk=input().rstrip().split(" ")
rsp=input().rstrip().split(" ")
t=input()
n=int(nk[0])
k=int(nk[1])
r=int(rsp[0])
s=int(rsp[1])
p=int(rsp[2])
point=0
sta="rskiped"

def read(l):
    global point
    global sta
    if sta=="rpointed":
        if l=="r":
            point+=0
            sta="rskiped"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=s
            sta="ppointed"
    elif sta=="spointed":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=0
            sta="sskiped"
        elif l=="p":
            point+=s
            sta="ppointed"
    elif sta=="ppointed":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=0
            sta="pskiped"
    elif sta=="rskiped" or sta=="sskiped" or sta=="pskiped":
        if l=="r":
            point+=p
            sta="rpointed"
        elif l=="s":
            point+=r
            sta="spointed"
        elif l=="p":
            point+=s
            sta="ppointed"
            
strs=[[] for i in range(k)]
for i in range(n):
    u=t[i:i+1]
    strs[i%k].append(u)
#print(strs)

for i in range(k):
    for j in range(len(strs[i])):
        read(strs[i][j])
        #print(sta)
        #print(point)
print(point)

Submission status: Wrong Answer

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

a = []
ans = 0
for i, s in enumerate(T):
    if s == "r":
        if i >= K and a[i - K] == "p":
            a.append("r")
        else:
            ans += P
            a.append("p")
    elif s == "s":
        if i >= K and a[i - K] == "r":
            a.append("s")
        else:
            ans += R
            a.append("r")
    elif s == "p":
        if i >= K and a[i - K] == "s":
            a.append("p")
        else:
            ans += S
            a.append("s")
print(ans)