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:
import numpy as np

N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input().replace('r', str(P)+' ').replace('s',str(R)+' ').replace('p',str(S)+' ')[:-1]
T=np.array(list(map(int, T.split())))

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

elif K!=1 and N%K!=0:
  T1=T[:N//K*K].reshape([N//K,K])
  T2=T[N//K*K:].reshape([1,-1])
  S1=np.vstack([T1[:,:N%K],T2])
  S2=T1[:,N%K:]

  for i in range(1,len(S1)):
    for j in range(S1.shape[1]):
      if S1[i,j]==S1[i-1,j]:S1[i,j]=0
  for i in range(1,len(S2)):
    for j in range(K-N%K):
      if S2[i,j]==S2[i-1,j]:S2[i,j]=0

  print(S1.sum()+S2.sum())

elif K!=1 and N%K==0:
  T=T.reshape([N//K,K])
  for i in range(1,len(T)):
    for j in range(T.shape[1]):
      if T[i,j]==T[i-1,j]:T[i,j]=0
  print(T.sum())

Submission status: Wrong Answer

Solution code:
import numpy as np

N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input().replace('r', str(P)+' ').replace('s',str(R)+' ').replace('p',str(S)+' ')[:-1]
T=np.array(list(map(int, T.split())))

if K!=1:
  T1=T[:N//K*K].reshape([N//K,K])
  T2=T[N//K*K:].reshape([1,-1])
  S1=np.vstack([T1[:,:N%K],T2])
  S2=T1[:,N%K:]

  for i in range(1,len(S1)):
    for j in range(S1.shape[1]):
      if S1[i,j]==S1[i-1,j]:S1[i,j]=0
  for i in range(1,len(S2)):
    for j in range(K-N%K):
      if S2[i,j]==S2[i-1,j]:S2[i,j]=0

  print(S1.sum()+S2.sum())
  
else:
  for i in range(1,N):
    if T[i]==T[i-1]:
      T[i]=0
  print(T.sum())

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
R,S,P=map(int,input().split())
point={}
point["r"]=R 
point["s"]=S
point["p"]=P 
t=list(input())
memory=[]
ans=0
for i in range(k):
    if t[i]=="r":
        ans+=point["p"]
        memory.append("p")
    elif t[i]=="s":
        ans+=point["r"]
        memory.append("r")
    else:
        ans+=point["s"]
        memory.append("s")
for j in range(k,n-k):
    if t[j]=="r" and memory[j-k]!="p":
        ans+=point["p"]
        memory.append("p")
    elif t[j]=="r" and memory[j-k]=="p":
        if t[k+j]=="s":
          memory.append("s")
        else:
          memory.append("r")
    elif t[j]=="s" and memory[j-k]!="r":
        ans+=point["r"]
        memory.append("r")
    elif t[j]=="s" and memory[j-k]=="r":
        if t[j+k]=="p":
          memory.append("p")
        else:
          memory.append("s")
    elif t[j]=="p" and memory[j-k]!="s":
        ans+=point["s"]
        memory.append("s")
    elif t[j]=="p" and memory[j-k]=="s":
        if t[j+k]=="r":
          memory.append("r")
        else:
          memory.append("p")
for j in range(n-k,n):
    if t[j]=="r" and memory[j-k]!="p":
        ans+=point["p"]
        memory.append("p")
    elif t[j]=="r" and memory[j-k]=="p":
        memory.append("r")
    elif t[j]=="s" and memory[j-k]!="r":
        ans+=point["r"]
        memory.append("r")
    elif t[j]=="s" and memory[j-k]=="r":
        memory.append("s")
    elif t[j]=="p" and memory[j-k]!="s":
        ans+=point["s"]
        memory.append("s")
    elif t[j]=="p" and memory[j-k]=="s":
        memory.append("p")
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
R,S,P=map(int,input().split())
point={}
point["r"]=R 
point["s"]=S
point["p"]=P 
t=list(input())
memory=[]
ans=0
for i in range(k):
    if t[i]=="r":
        ans+=point["p"]
        memory.append("p")
    elif t[i]=="s":
        ans+=point["r"]
        memory.append("r")
    else:
        ans+=point["s"]
        memory.append("s")
for j in range(k,n-k):
    if t[j]=="r" and memory[j-k]!="p":
        ans+=point["p"]
        memory.append("p")
    elif t[j]=="r" and memory[j-k]=="p":
        if t[k+j]=="s":
          memory.append("s")
        else:
          memory.append("r")
    elif t[j]=="s" and memory[j-k]!="r":
        ans+=point["r"]
        memory.append("r")
    elif t[j]=="s" and memory[j-k]=="r":
        if t[j+k]=="p":
          memory.append("p")
        else:
          memory.append("s")
    elif t[j]=="p" and memory[j-k]!="s":
        ans+=point["s"]
        memory.append("s")
    elif t[j]=="p" and memory[j-k]=="s":
        if t[j+k]=="r":
          memory.append("r")
        else:
          memory.append("p")
for j in range(n-k,n):
    if t[j]=="r" and memory[j-k]!="p":
        ans+=point["p"]
        memory.append("p")
    elif t[j]=="r" and memory[j-k]=="p":
        memory.append("r")
    elif t[j]=="s" and memory[j-k]!="r":
        ans+=point["r"]
        memory.append("r")
    elif t[j]=="s" and memory[j-k]=="r":
        memory.append("s")
    elif t[j]=="p" and memory[j-k]!="s":
        ans+=point["s"]
        memory.append("s")
    elif t[j]=="p" and memory[j-k]=="s":
        memory.append("p")
  
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
R,S,P=map(int,input().split())
point={}
point["r"]=R 
point["s"]=S
point["p"]=P 
t=list(input())
memory=[]
ans=0
for i in range(k):
    if t[i]=="r":
        ans+=point["p"]
        memory.append("p")
    elif t[i]=="s":
        ans+=point["r"]
        memory.append("r")
    else:
        ans+=point["s"]
        memory.append("s")
for j in range(k,n):
    if t[j]=="r" and memory[j-k]!="p":
        ans+=point["p"]
        memory.append("p")
    elif t[j]=="r" and memory[j-k]=="p":
        memory.append("r")
    elif t[j]=="s" and memory[j-k]!="r":
        ans+=point["r"]
        memory.append("r")
    elif t[j]=="s" and memory[j-k]=="r":
        memory.append("s")
    elif t[j]=="p" and memory[j-k]!="s":
        ans+=point["s"]
        memory.append("s")
    elif t[j]=="p" and memory[j-k]=="s":
        memory.append("p")
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
d={'r':p,'s':r,'p':s}
d_={'r':'p','s':'r','p':'s'}
s=0
for i in range(k):
  a=0
  z='0'
  t_=t[i::k]
  for a in range(len(t_)):
    if a==0:
      s+=d[t_[a]]
      z=d_[t_[a]]
      a+=1
    else:
      if z==d_[t_[a]]:
        z=t_[a]
        a+=1
      else:
        s+=d[t_[a]]
        z=d_[t_[a]]
        a+=1
print(s)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
ans=0
dic={'r':'p','s':'r','p':'s'}
score={'r':R,'s':S,'p':P}
past=[]
for i in range(len(T)):
    if i>=K:
        if dic[T[i]]==past[i-K]:
            past.append(T[i])
            continue
        else:
            ans+=score[dic[T[i]]]
            past.append(dic[T[i]])
    else:
        ans+=score[dic[T[i]]]
        past.append(dic[T[i]])
print(ans)

Submission status: Wrong Answer

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

dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
    if i <= K:
        dp[i][0] = int(T[i-1]=='s') * R
        dp[i][1] = int(T[i-1]=='p') * P
        dp[i][2] = int(T[i-1]=='r') * P
    else:
        dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + int(T[i-1]=='s') * R
        dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + int(T[i-1]=='p') * P
        dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + int(T[i-1]=='r') * S

ans = 0
for d in dp[-K:]:
    ans += max(d)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
slist = ['']*k
for i in range(n):
    slist[i%k] += T[i]

ans = 0
for s in slist:
    dp = [[0,0,0]for i in range(len(s))]
    #dp[i][j] = 直前にｊを出したときの得点の最大値
    '''
    0..r
    1..s
    2..p
    '''
    dp[0][1] = S if s[0] == 'p' else 0
    dp[0][0] = R if s[0] == 's' else 0
    dp[0][2] = P if s[0] == 'r' else 0

    for i in range(1,len(s)):
        if s[i] == 'r':
            dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + P
            dp[i][1] = max(dp[i-1][0],dp[i-1][2])
            dp[i][0] = max(dp[i-1][1],dp[i-1][2])
        elif s[i] == 's':
            dp[i][0] = max(dp[i-1][2],dp[i-1][1]) + R
            dp[i][1] = max(dp[i-1][0],dp[i-1][2])
            dp[i][2] = max(dp[i-1][1],dp[i-1][0])
        else:
            dp[i][1] = max(dp[i-1][2],dp[i-1][0]) + S
            dp[i][0] = max(dp[i-1][1],dp[i-1][2])
            dp[i][2] = max(dp[i-1][1],dp[i-1][0])
    
    ans += max(dp[len(s)-1][0],dp[len(s)-1][1],dp[len(s)-1][2])
print(slist)
print(ans)

'''
解説AC...
'''

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:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
5 2
8 7 6
rsrpr

7 1
100 10 1
ssssppr
rprpsps
rprpsrp
'''

def solve(n,k,R,S,P,s):
	n = len(s)
	score = 0
	move = ''
	for i in range(n):
		if(i < k):
			if(s[i] == 'r'):
				move += 'p'
				score += P
			if(s[i] == 'p'):
				move += 's'
				score += S
			if(s[i] == 's'):
				move += 'r'
				score += R
		else:
			if(s[i] == 'r'):
				if(move[i-k] != 'p'):
					move += 'p'
					score += P
				else:
					if(R >= S):
						move += 'r'
					else:
						move += 's'
			if(s[i] == 'p'):
				if(move[i-k] != 's'):
					move += 's'
					score += S
				else:
					if(P >= R):
						move += 'p'
					else:
						move += 'r'
			if(s[i] == 's'):
				if(move[i-k] != 'r'):
					move += 'r'
					score += R
				else:
					if(S >= P):
						move += 's'
					else:
						move += 'p'
	# print('move:',move)
	return score


N,K = list(map(int, stdin.readline().rstrip().split()))
R,S,P = list(map(int, stdin.readline().rstrip().split()))
T = input()
ans = solve(N,K,R,S,P,T)
print(ans)

Submission status: Wrong Answer

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
5 2
8 7 6
rsrpr

7 1
100 10 1
ssssppr
rprpsrp
'''

def solve(n,k,R,S,P,s):
	n = len(s)
	score = 0
	move = ''
	for i in range(n):
		if(i < k):
			if(s[i] == 'r'):
				move += 'p'
				score += P
			if(s[i] == 'p'):
				move += 's'
				score += S
			if(s[i] == 's'):
				move += 'r'
				score += R
		else:
			if(s[i] == 'r'):
				if(move[i-k] != 'p'):
					move += 'p'
					score += P
				else:
					move += 'r'
			if(s[i] == 'p'):
				if(move[i-k] != 's'):
					move += 's'
					score += S
				else:
					move += 'p'
			if(s[i] == 's'):
				if(move[i-k] != 'r'):
					move += 'r'
					score += R
				else:
					move += 's'
	return score


N,K = list(map(int, stdin.readline().rstrip().split()))
R,S,P = list(map(int, stdin.readline().rstrip().split()))
T = input()
ans = solve(N,K,R,S,P,T)
print(ans)

Submission status: Wrong Answer

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
5 2
8 7 6
rsrpr
'''

def solve(n,k,R,S,P,s):
	n = len(s)
	score = 0
	move = ''
	for i in range(n):
		if(i < k):
			if(s[i] == 'r'):
				move += 'p'
				score += P
			if(s[i] == 'p'):
				move += 's'
				score += S
			if(s[i] == 's'):
				move += 'r'
				score += R
		else:
			if(s[i] == 'r'):
				if(move[i-k] != 'p'):
					move += 'p'
					score += P
				else:
					move += 'r'
			if(s[i] == 'p'):
				if(move[i-k] != 's'):
					move += 's'
					score += S
				else:
					move += 'p'
			if(s[i] == 's'):
				if(move[i-k] != 'r'):
					move += 'r'
					score += R
				else:
					move += 'p'
	# print('move:',move)
	return score


N,K = list(map(int, stdin.readline().rstrip().split()))
R,S,P = list(map(int, stdin.readline().rstrip().split()))
T = input()
ans = solve(N,K,R,S,P,T)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()
prev = {}

ans = 0
for i in range(k):
    if t[i] == 'r':
        ans += P
        prev[i] = 'p'
    elif t[i] == 's':
        ans += R
        prev[i] = 'r'
    elif t[i] == 'p':
        ans += S
        prev[i] = 's'

for i in range(k, n):
    a = i % k
    if t[i] == 'r':
        if prev[a] != 'p':
            ans += P
            prev[a] = 'p'
        else:
            prev[a] = 'r'
    elif t[i] == 's':
        if prev[a] != 'r':
            ans += R
            prev[a] = 'r'
        else:
            prev[a] = 's'
    elif t[i] == 'p':
        if prev[a] != 's':
            prev[a] = 's'
            ans += S
        else:
            prev[a] = 'p'
print(ans)

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

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

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

enemy_hands = input()


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

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


point = 0

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

        if win:
            point += win_point[hand]
            now_hands = next_hands[hand]
        else:
            # 勝てない場合次似邪魔しない手を選ぶ
            # 勝てない回の次は必ず勝てるため全手出せる前提とする
            now_hans = ['r', 'p', 's']

print(point)

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

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

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

enemy_hands = input()


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

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


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

    win, hand = can_win(next_enemy_hand, enemy_hand)

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


point = 0

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

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

print(point)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, K = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()]

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

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

enemy_hands = input()


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

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


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

    win, hand = can_win(next_enemy_hand, enemy_hand)

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


point = 0

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

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

print(point)

Submission status: Wrong Answer

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

t2 = [[] for _ in range(k)]
score = [0]*n
for i,c in enumerate(t):
  t2[i%k].append(c)
score = {'r':p,'s':r,'p':s}
total = 0
for t3 in t2:
  if len(t3)==0: continue
  if len(t3)==1:
    total += score[c]
    continue  
  for i in range(len(t3)-1):
    if t3[i] == 'e': continue
    total += score[t3[i]]
    if t3[i] == t3[i+1]:
      t3[i+1]='e'
  if t3[-1] != 'e':
    total += score[t3[-1]]
print(total)

Submission status: Wrong Answer

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

i = 0
while len(T) > i+K:
  if T[i] == T[i+K]:
    if len(T) > i+K+1:
      T = T[:i+K] + T[i+K+1:]
    else:
      T = T[:i+K]
  i += 1

score = 0
for i in range(len(T)):
  if T[i] == 'r':
    score += P
  elif T[i] == 's':
    score += R
  else:
    score += S
    
print(score)

Submission status: Wrong Answer

Solution code:
def choose_hand(last,next):
    for j in ['r','s','p']:
        if j!=last and j!=next:
            return j

n,k = map(int,input().split())
r,s,p = map(int,input().split())
points = {'r':r, 's':s, 'p':p}
hands = {'r':'p', 's':'r', 'p':'s'}
t = list(input())
rpsList = ['']*n
ans = 0

for i,hand in enumerate(t):
    rpsList[i] += hands[hand]
    if i>=k and rpsList[i]==rpsList[i-k]:
        lastHand = rpsList[i-k]
        nextHand = rpsList[i+k] if i+k<n  else ''
        rpsList[i] = choose_hand(lastHand,nextHand)
    else:
        ans += points[rpsList[i]]

print(ans)

Submission status: Wrong Answer

Solution code:
def choose_hand(last,next):
    result = ''
    for j in ['r','s','p']:
        if j!=last and j!=next:
            result = j
            break
    return result

n,k = map(int,input().split())
r,s,p = map(int,input().split())
points = {'r':r, 's':s, 'p':p}
hands = {'r':'p', 's':'r', 'p':'s'}
t = list(input())
rpsList = ['']*n
ans = 0

for i in range(n):
    rpsList[i] += hands[t[i]]
    if i>=k and rpsList[i]==rpsList[i-k]:
        lastHand = rpsList[i-k]
        nextHand = rpsList[i+k] if i+k<n  else ''
        rpsList[i] = choose_hand(lastHand,nextHand)
    else:
        ans += points[rpsList[i]]

print(ans)

Submission status: Wrong Answer

Solution code:
def choose_hand(last,next):
    result = ''
    for j in ['r','s','p']:
        if j!=last and j!=next:
            result = j
            break
    return result

n,k = map(int,input().split())
r,s,p = map(int,input().split())
points = {'r':r, 's':s, 'p':p}
hands = {'r':'p', 's':'r', 'p':'s'}
t = list(input())
rpsList = ['']*n
ans = 0

for i in range(n):
    rpsList[i] += hands[t[i]]
    if i-k>=0 and rpsList[i]==rpsList[i-k]:
        lastHand = rpsList[i-k]
        nextHand = rpsList[i+k] if i+k<n  else ''
        rpsList[i] = choose_hand(lastHand,nextHand)
    else:
        ans += points[rpsList[i]]

print(ans)

Submission status: Wrong Answer

Solution code:
def check_hands(last,next):
    result = ''
    for j in ['r','s','p']:
        if j!=last and j!=next:
            result = j
            break
    print(result)
    return result

n,k = map(int,input().split())
r,s,p = map(int,input().split())
points = {'r':r, 's':s, 'p':p}
hands = {'r':'p', 's':'r', 'p':'s'}
t = list(input())
rpsList = ['']*n
ans = 0

for i in range(n):
    rpsList[i] += hands[t[i]]
    if i-k>=0 and rpsList[i]==rpsList[i-k]:
        lastHand = rpsList[i-k]
        nextHand = rpsList[i+k] if i+k<n  else ''
        rpsList[i] = check_hands(lastHand,nextHand)
    else:
        ans += points[rpsList[i]]

print(ans)

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

point =0
player =[]
Z =0 #負けか引き分け
for i in range(N):
    #K回以前は勝つ
    if i <K :
        if T[i]=="r":
            player.append(P)
            point +=P
        if T[i]=="s":
            player.append(R)
            point +=R
        if T[i]=="p":
            player.append(S)
            point +=S
    #k回以後は以前の結果を見て
    else:
        if T[i]=="r":
            if player[i-K] !=P :
                player.append(P)
                point +=P
            else:#勝てないときは、以後の結果を「察知」、後で勝てるように今の手を決める
                player.append(Z)
        elif T[i]=="s":
            if player[i-K] !=R :
                player.append(R)
                point +=R
            else:#勝てないときは、以後の結果を「察知」、後で勝てるように今の手を決める
                player.append(Z)
        if T[i]=="p":
            if player[i-K] !=S :
                player.append(S)
                point +=S
            else:#勝てないときは、以後の結果を「察知」、後で勝てるように今の手を決める
                player.append(Z)  
print(point)

Submission status: Wrong Answer

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

ans = []
for i in range(N):
    if T[i] == 's':
        ans.append('r')
    elif T[i] == 'r':
        ans.append('p')
    elif T[i] == 'p':
        ans.append('s')

    if i >= K:
        if ans[i-K] == ans[i]:
            ans[i] = T[i]


count = 0
for i in range(N):
    # あいこ処理　
    if T[i] == ans[i]:
        continue

    if ans[i] == 'r':
        count += R
    elif ans[i] == 's':
        count += S
    elif ans[i] == 'p':
        count += P

print(count)

Submission status: Wrong Answer

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

ans = []
for i in range(N):
    if T[i] == 's':
        ans.append('r')
    elif T[i] == 'r':
        ans.append('p')
    elif T[i] == 'p':
        ans.append('s')


for i in range(N):
    if ans[i] == ans[i-K]:
        ans[i] = T[i]
count = 0
for i in range(N):
    # あいこ処理　
    if T[i] == ans[i]:
        continue

    if ans[i] == 'r':
        count += R
    elif ans[i] == 's':
        count += S
    elif ans[i] == 'p':
        count += P

print(count)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t = input()
d = [0]*3*10**5
for i in range(n):
  if t[i] == 'r':
    d[i] = 2*10**4+p
  if t[i] == 's':
    d[i] = 4*10**4+r
  if t[i] == 'p':
    d[i] = 6*10**4+s
ans = 0
for i in range(n):
  if d[i] == d[k+i]:
    d[k+i] = 0
  ans += d[i]%(10**4)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t = input()
d = [0]*2*10**5
for i in range(n):
  if t[i] == 'r':
    d[i] = p
  if t[i] == 's':
    d[i] = r
  if t[i] == 'p':
    d[i] = s
for i in range(n):
  if d[i] == d[k+i]:
    d[k+i] = 0
print(sum(d))

Submission status: Wrong Answer

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

did = "-" * k
ans = 0
for i in t:
    if i == "r":
        if did[-k] == "p":
            did += "r"
        else:
            did += "p"
            ans += p
    elif i == "s":
        if did[-k] == "r":
            did += "s"
        else:
            did += "r"
            ans += r
    else:
        if did[-k] == "s":
            did += "p"
        else:
            did += "s"
            ans += s

print(ans)

Submission status: Wrong Answer

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

def main():
    n, k = input_list()
    # R = グー, S = チョキ, P = パー
    R, S, P = input_list()
    t = input()
    ans = 0
    ng = ""
    hands = []
    for i, w in enumerate(t):
        if i > k - 1:
            ng = hands[i-k]
        h = ""
        if w == "r":
            h = "p"
            if ng == h:
                hands.append(w)
                continue
            ans += P
        elif w == "s":
            h = "r"
            if ng == h:
                hands.append(w)
                continue
            ans += R
        elif w == "p":
            h = "s"
            if ng == h:
                hands.append(w)
                continue
            ans += S

        hands.append(h)
    print(ans)


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


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


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

ans = 0
memo = [0]*n
for i in range(n):
    if t[i] == "r":
        if memo[max(0,i-k)] == 1:
            pass
        else:
            ans += p
            memo[i] = 1
    elif t[i] == "s":
        if memo[max(0,i-k)] == 2:
            pass
        else:
            ans += r
            memo[i] = 2
    else:
        if memo[max(0,i-k)] == 3:
            pass
        else:
            ans += s
            memo[i] = 3
print(ans)