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()
res = 0
te_log = []

def judg(te):
  if te == "r":
    return "p"
  if te == "s":
    return "r"
  if te == "p":
    return "s"

def score(te):
  if te == "r":
    return r
  if te == "s":
    return s
  if te == "p":
    return p
  
for i in range(n):
  if i+1 <= k:
    res += score(judg(t[i]))
    te_log.append(judg(t[i]))
    continue
  comp = t[i]
  no = te_log[i-k]
  me = judg(comp)
  if no == me:
    te_log.append(comp)
    continue
  res += score(me)
  te_log.append(me)

print(res)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as DD
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

D = DD(int)
D["s"] = R
D["p"] = S
D["r"] = P

A = [0,0,0]

A[0] = max(D, key=D.get)
A[2] = min(D, key=D.get)
A[1] = "spr".replace(A[0], "").replace(A[2], "")

C = [0,0,0]
ans = 0
for i in range(N):
  C = list(map(lambda x: max(x-1,0), C))
  if T[i] == A[0] and C[0] == 0:
    ans += D[A[0]]
    C[0] = K+1
  elif T[i] == A[1] and C[1] == 0:
    ans += D[A[1]]
    C[1] = K+1
  elif T[i] == A[2] and C[2] == 0:
    ans += D[A[2]]
    C[2] = K+1
print (ans)

Submission status: Wrong Answer

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


hands = ''
for i in range(n):
    if t[i] == 'r':
        hands += 'p'
    elif t[i] == 'p':
        hands += 's'
    else:
        hands += 'r'


for i in range(k,n):    
    if hands[i] == hands[i-k]:
        hands = hands[:i] + t[i] + hands[i+1:]

cnt = 0
for i in range(n):
    if (hands[i]=='r')&(t[i]=='s'):
        cnt += r
    elif (hands[i]=='s')&(t[i]=='p'):
        cnt += s
    elif (hands[i]=='p')&(t[i]=='r'):
        cnt += p
print(cnt)

Submission status: Wrong Answer

Solution code:
# K回前と現在の問いが同じだったら0点

str1 = input().split(" ")
str2 = input().split(" ")
t = list(input())

n = int(str1[0])
k = int(str1[1])

r = int(str2[0])
s = int(str2[1])
p = int(str2[2])

result = 0
hoge = 0
for i in range(0,n):
    if i < k:
        continue

    j = i-k
    if t[i] == t[j]:
        t[i] = "_"

print(t)
pres = p * t.count("r")
rres = r * t.count("s")
sres = s * t.count("p")

print(pres + rres + sres)

Submission status: Wrong Answer

Solution code:
#constants
Rock = 1
Paper = 2
Scissors = 3

#Define the main function
def main():

    #set control loop
    keep_going = 'Y'


    #set counter to zero
    computer_wins = 0
    player_wins = 0
    tie_score = 0

    #call display message
    display_message()

    while keep_going == 'y' or keep_going == 'Y':

        play_game()


        #prompt user to keep going
        keep_going = input('would you like to play again? (Y for Yes): ')

    print('The computer won', computer_wins, 'times')
    print('The player won', player_wins, 'times')
    print('There were', tie_score, 'tie scores')

def play_game():

    #get random input
    computer = get_random()

    #get the players input
    play = get_play()

    #validate input
    if play == '1' or play == '2' or play == '3':
        play == True
    else:
        play == False
        print('Error: Invalid Entry')
        play = input('Please enter 1 for Rock, 2 for Paper, or 3 for Scissors: ')

    if play == computer:
        print('Tie Score, Please try again')
        tie_score += 1

    else:
        get_score(computer, play)

    print('The computer chose:', computer)
    print('The player chose: ', play)


#define display message
def display_message():
    print('Welcome to Rock Paper Scissors, a game of chance to see who will')
    print('outsmart the other. This game is Man VS Computer.')
    print('The program will select a random integer and then ask you for an integer')
    print('1 for Rock 2 for paper or 3 for Scissors. The program will then tell')
    print('you who won the game.')
    print('GOOD LUCK!')
    print
    print

def get_random():
    import random

    #generate random int
    computer = random.randint(1, 3)
    return computer


def get_play():
    #prompt user to enter an integer 1, 2, or 3
    play = input('Select 1 for Rock, 2 for Paper, or 3 for Scissors: ')
    return play

def get_score(computer, play):

    if computer == 1 and play == 2:
        score = 'player wins'
        print('Paper covers Rock, Player Wins')
        #player wins
        player_wins += 1

    elif computer == 1 and play == 3:
        score = 'computer wins'
        print('Scissors cut Paper, Computer Wins')
        #computer wins
        computer_wins += 1


    elif computer == 2 and play == 1:
        score = 'computer wins'
        print('Paper covers Rock, Computer Wins')
        #computer wins
        computer_wins += 1

    elif computer == 2 and play == 3:
        score = 'player wins'
        print('Scissors cut Paper, Player Wins')
        #player wins
        player_wins += 1


    elif computer == 3 and play == 1:
        score = 'player wins'
        print('Rock smashes Scissors, Player Wins')
        #player wins
        player_wins += 1

    elif computer == 3 and play == 2:
        score = 'computer wins'
        print('Scissors cut Paper, Computer Wins')
        #computer wins
        computer_wins += 1


#call main function
main()

Submission status: Wrong Answer

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

r = [0] * N
s = [0] * N
p = [0] * N

for i,j in enumerate(T):
    if j == "r":
        r[i] = 1
        continue
    if j == "s":
        s[i] = 1
        continue
    if j == "p":
        p[i] = 1

total = 0

chk = 0
for i in r:
    if i and chk == 0:
        total += scores["r"]
        chk = K
    else:
        chk -= 1 if chk > 0 else 0

chk = 0
for i in s:
    if i and chk == 0:
        total += scores["s"]
        chk = K
    else:
        chk -= 1 if chk > 0 else 0

chk = 0
for i in p:
    if i and chk == 0:
        total += scores["p"]
        chk = K
    else:
        chk -= 1 if chk > 0 else 0
    
print(total)

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

hand = {
    "s": R,
    "p": S,
    "r": P,
}

hands = sorted(
    hand.items(), key=lambda x: x[1],
    reverse=True
)
r = np.zeros(n)
ans = 0
for j in range(3):
    a = hands[j][0]
    b = hands[j][1]
    for i in range(n):
        if t[i] == a:
            if t[i-k] == a and i > k and r[i-k] == 1:
                continue
            else:
                ans += b
                r[i] = 1
        else:
            continue
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
winners_nums = sorted([R, S, P])
winners = Counter({R:'r', S: 's', P: 'p'})

min_winner = winners.get(winners_nums[0])
second_min = winners.get(winners_nums[1])
mapping = {'r': 'p', 's': 'r', 'p': 's'}

ans = 0
done = []
for t in T:
    win = mapping.get(t)
    if len(done) >= K:
        if done[len(done) - K] == win:
            if len(T) > len(done) + K and mapping.get(T[len(done) + K]) != min_winner:
                done.append(min_winner)
            elif len(T) > len(done) + K and mapping.get(T[len(done) + K]) != second_min:
                done.append(second_min)
            else:
                done.append(win)
            continue
    if win =='r':
        ans += R
    elif win == 's':
        ans += S
    else:
        ans += P
    done.append(win)
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
kr = 1
ks= 1
kp = 1
Is = 0
Ir=0
Ip=0
A =[]

for i in range(n):
  if i-k < 0:
      A.append(1)
      if t[i] == "r":
        kr = 1
        ans += p
      elif t[i] == "s":
        ks=1
        ans += r
      else:
        kp=1
        ans += s
  else:
    if t[i] != t[i-k]:
      if t[i] == "r":
        kr=1
        ans += p
        Ir = i
        A[i%k]=1
      elif t[i] == "s":
        ans += r
        ks=1
        Is = i
        A[i%k]=1
      else:
        kp=1
        ans += s
        A[i%k]=1
    else:
      if t[i] == "r":
        if A[i%k] == 0:
          ans+=p
          A[i%k] = 1
        else:
            A[i%k]  = 0
      elif t[i] == "s":
        if A[i%k] ==0:
          ans += r
          A[i%k] = 1
        else:
            A[i%k] = 0
      else:
        if A[i%k]==0:
          ans+=s
          kp=1
          Ip = i
          A[i%k] = 1
        else: 
            A[i%k] = 0
  print(ans,t[i],A,i+1)
      
print(ans)

Submission status: Wrong Answer

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

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

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

T = input()
H = []
score = 0

def janken(hands):
    if hands == 'r':
        my_hand = 'p'
    
    elif hands == 's':
        my_hand = 'r'
    
    else:
        my_hand = 's'

    return(my_hand)

def my_score(hands):
    if hands == 'r':
        my_score = R
    
    elif hands == 's':
        my_score = S
    
    else:
        my_score = P

    return(my_score)


for i in range(N):
    x = janken(T[i])
    H.append(x)
    score += my_score(x)


for j in range(K,N-K):
    if H[j-K] == H [j]:
        score -= my_score(H[j])

        H[j] = janken(H[j])
        
        if H[j] == H[j + K]:
            H[j] = janken(H[j])
        
for k in range(N-K,N):
    if H[k-K] == H [k]:
        score -= my_score(H[k])

        H[k] = janken(H[k])

print(score)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
R,S,P = map(int,input().split())
Ts = np.array(list(str(input())))
T = np.zeros(N,dtype=int)

T[Ts=='r'] = P
T[Ts=='s'] = R
T[Ts=='p'] = S
for i in range(K, N):
    if T[i]==T[i-K]:
        T[i] = 0

print(np.sum(T))

Submission status: Wrong Answer

Solution code:
try:
    N,K = map(int,input().split())
    R,S,P = map(int,input().split())
    T = str(input())
    janken = {"r":"p","s":"r","p":"s"}
    point = {"r":P,"s":R,"p":S}
    kekka = []
    ans = 0

    for i in range(K):
        kekka.append(janken[T[i]]) 
        ans += point[T[i]]

    for i in range(K,N):
        if janken[T[i]] == kekka[i-K]:
            kekka.append(T[i])
        else:
            kekka.append(janken[T[i]])
            ans += point[T[i]]

    print(ans)
    
except EOFError:
    pass

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
# Kを無視した勝ち手のリスト
kachite = []
for i in range(N):
  if T[i] == 'r':
    kachite.append(P)
  elif T[i] == 's':
    kachite.append(R)
  else:
    kachite.append(S)

# 勝ち手リストを頭から見ていき、iとi-Kの勝ち手が同じ場合は変更する
for j in range(N):
  if j-K>=0:
    if kachite[j]==kachite[j-K] and kachite[j-K]!=0:
      #K回前の勝ち手が同じ(得点が同じ)、かつ、0点ではない場合
      kachite[j] = 0 # K回前、K回後のいずれでもない手を出したことにする
# 最終得点を出力
print(sum(kachite))

Submission status: Wrong Answer

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

from collections import Counter
winners_nums = sorted([R, S, P])
winners = Counter({R:'r', S: 's', P: 'p'})




min_winner = winners.get(winners_nums[0])
second_min = winners.get(winners_nums[1])
mapping = {'r': 'p', 's': 'r', 'p': 's'}


ans = 0
done = []
for t in T:
    win = mapping.get(t)
    if len(done) >= K:
        if done[len(done) - K] == win:
            if len(T) > len(done) + K and mapping.get(T[len(done) + K]) != min_winner:
                done.append(min_winner)
            else:
                done.append(second_min)
            continue
    if win =='r':
        ans += R
    elif win == 's':
        ans += S
    else:
        ans += P
    done.append(win)
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
s, p, r = map(int, input().split())
T = [t for t in 'a'*K + input()]
h = {'r':'s', 's':'p', 'p':'r'}
G = []
for n in range(K, N+K):
    if T[n] == T[n-K]:
        T[n] = h[T[n]]
        G.append(T[n])

print(r*T.count('r')+p*T.count('p')+s*T.count('s') - (r*G.count('r')+p*G.count('p')+s*G.count('s')))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n, k = (int(i) for i in input().split())
r, s, p = (int(i) for i in input().split())
t=str(input())
hands=[]

for i in range(0,n):
    if t[i] == "r":
        hand = "p"
    elif t[i] == "s":
        hand = "r"
    else :
        hand = "s"

    if i - k >= 0:
        if hand == hands[i-k]:
            if i+k < n:
                if t[i] == t[i+k]:
                    # あいこ
                    if t[i+k] == "r":
                        hand = "r"
                    if t[i+k] == "s":
                        hand = "s"
                    if t[i+k] == "p":
                        hand = "p"
                else:
                    # 負け
                    if t[i+k] == "r":
                        hand = "s"
                    if t[i+k] == "s":
                        hand = "p"
                    if t[i+k] == "p":
                        hand = "r"
    hands.append(hand)

score=0
for hand in hands:
    if hand == "r":
        score+=r
    elif hand == "s":
        score+=s
    else:
        score+=p
print (score)

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()
sum=0
hands=''
for i in range(K):

    if T[i] == 'r':
        sum+=P
        hands+='p'
    elif T[i] == 's':
        sum+=R
        hands+='r'
    elif T[i] == 'p':
        sum+=S
        hands+='s'

for i in range(K,N-K):

    if T[i] == 'r':
        if hands[i-K] != 'p':
            sum+=P
            hands+='p'
        elif hands[i-K] =='p' and T[i+K] =='s':
            hands+='s'
        else: hands+='r'

    elif T[i] == 's':
        if hands[i-K] != 'r':
            sum+=R
            hands+='r'
        elif hands[i-K] == 'r' and T[i+K] == 'p':
            hands+='p'
        else:
            hands+='s'

    elif T[i] == 'p':
        if hands[i-K] != 's':
            sum+=S
            hands+='s'
        elif hands[i-K] =='s' and T[i+K] == 'r':
            hands+='r'
        else:
            hands+='p'

for i in range(N-K,N):
    if T[i] == 'r':
        if hands[i-K] != 'p':
            sum+=P
            hands+='p'
        else: hands+='r'

    elif T[i] == 's':
        if hands[i-K] != 'r':
            sum+=R
            hands+='r'
        else:
            hands+='s'

    elif T[i] == 'p':
        if hands[i-K] != 's':
            sum+=S
            hands+='s'
        else:
            hands+='p'
print(sum)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
A = 0
result = 0
counts_r = 0
counts_s = 0
counts_p = 0
for i in range(N):
    #print(i)
    counts_r += 1
    counts_s += 1
    counts_p += 1
    A += 1
    if A <= K:
        if T[i] == "r":
            result += P
        elif T[i] == "s":
            result += R
        else:
            result += S
    else:
        if T[i] != T[i-K]:
            #print(T[i],T[i-K])
            if T[i] == "r":
                result += P
                counts_r = 0
            elif T[i] == "s":
                result += R
                counts_s = 0
            else:
                result += S
                counts_p = 0
        else:
            if T[i] == T[i-2*K] and counts_r > 2*K:
                if T[i] == "r":
                    result += P
                    counts_r = 0
            if T[i] == T[i - 2 * K] and counts_s > 2 * K:
                if T[i] == "s":
                    result += R
                    counts_s = 0
            if T[i] == T[i - 2 * K] and counts_r > 2 * K:
                if T[i] == "p":
                    result += S
                    counts_p = 0


    #print(result)
print(result)
'''
20 4
10 1000 1
rsppsprpsssrsrprprsp
'''

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()]
w = {'r': ('p', P), 's': ('r', R), 'p': ('s', S)}
T = list(input())
p = []
ans = 0
for i, c in enumerate(T):
    if i<K:
        ans += w[c][1]
        p.append(w[c][0])
    else:
        if p.pop(0)!=w[c][0]:
            ans += w[c][1]
            p.append(w[c][0])
        else:
            p.append(c)
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()
z = {'r': p, 's': r, 'p': s}
x = []
for a in t:
    x.append(z[a])
for i in range(k):
    for j in range(k + i, n, k):
        if x[j] == x[j - k]:
            x[j] = 0
print(sum(x))

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()
dic =dict()
my = []
dic["r"] = ("p",p)
dic["s"] = ("r",r)
dic["p"] = ("s",s)

total = 0

for i in range(len(t)) :
  
  t1 = t[i]
  
  l = i - k
  
  if l < 0 :
    
    total += dic[t1][1]
    my.append(dic[t1][0])
    
  else :
    

    if dic[t1][0] == my[l] :

      my.append(t1)
      
    else :
      
      total += dic[t1][1]
      my.append(dic[t1][0])
      
print(total)

Submission status: Wrong Answer

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

for i in range(n):
    if t[i] == "r":
        point.append(p)
    elif t[i] == "s":
        point.append(r)
    else:
        point.append(s)

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

print(sum(point))

Submission status: Wrong Answer

Solution code:
#############################
#
# じゃんけん説明
# r: グー
# s: チョキ
# p: パー
#
#############################
#
# 入力r -> 勝利時の グー の点数
# 入力s -> 勝利時の チョキ の点数
# 入力p -> 勝利時の パー の点数
#
#############################

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

MY_HAND = []
ANS = 0

def can_not_use_hand(after_k_hand):
  if after_k_hand == 'r':
    return 'p'
  if after_k_hand == 's':
    return 'r'
  if after_k_hand == 'p':
    return 's'

for battle_time in range(n):
  if battle_time < k:
    if t[battle_time] == "r":
      MY_HAND.append("p")
      ANS += p
    
    if t[battle_time] == "s":
      MY_HAND.append("r")
      ANS += r
    
    if t[battle_time] == "p":
      MY_HAND.append("s")
      ANS += s
  else:
    if t[battle_time] == "r":
      if MY_HAND[battle_time-k] == "p":
        if can_not_use_hand(t[battle_time]) == 'r':
          MY_HAND.append("s")
          ANS += 0
        else:
          MY_HAND.append("r")
          ANS += 0
      else:
        MY_HAND.append("p")
        ANS += p

    if t[battle_time] == "s":
      if MY_HAND[battle_time-k] == "r":
        if can_not_use_hand(t[battle_time]) == 's':
          MY_HAND.append("p")
          ANS += 0
        else:
          MY_HAND.append("s")
          ANS += 0
      else:
        MY_HAND.append("r")
        ANS += r
    
    if t[battle_time] == "p":
      if MY_HAND[battle_time-k] == "s":
        if can_not_use_hand(t[battle_time]) == 'p':
          MY_HAND.append("r")
          ANS += 0
        else:
          MY_HAND.append("p")
          ANS += 0
      else:
        MY_HAND.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()

# N,K=7 ,1
# R,S,P=100 ,10, 1
# T="ssssppr"

# N,K=5, 2
# R,S,P=8, 7, 6
# T="rsrpr"

# N,K=30, 5
# R,S,P=325, 234, 123
# T="rspsspspsrpspsppprpsprpssprpsr"


max_ans=T.count("s")*R+T.count("p")*S+T.count("r")*P
flag=0
for i in range(K):
    tmp_ans=T[i::K]
    for i in range(len((tmp_ans))-1):
        if flag==1:
            flag=0
            continue
        if tmp_ans[i]==tmp_ans[i+1]:
            if tmp_ans[i]=="s":
                max_ans-=R
            if tmp_ans[i]=="p":
                max_ans-=S
            if tmp_ans[i]=="r":
                max_ans-=P
            flag=1

print(max_ans)


# for i in range(K):
#     tmp_ans=T[i::K]
#     for i in range(len((tmp_ans))-1):
#         if tmp_ans[i]==tmp_ans[i+1]:
#             if tmp_ans[i]=="s":
#                 max_ans-=R
#             if tmp_ans[i]=="p":
#                 max_ans-=S
#             if tmp_ans[i]=="r":
#                 max_ans-=P
#             tmp_ans = tmp_ans[:i+1] + 'X' +tmp_ans[i+2:]

# print(max_ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=[i for i in input()]
H=[]
sum=0
if N<=K:#K回目は気にしない
    for i in T:
        if i=="r":
            sum+=P
        elif i=="s":
            sum+=R
        else:
            sum+=S
else:
    for i in range(K):
        if T[i]=="r":
            H.append("p")
            sum+=P
        elif T[i]=="s":
            H.append("r")
            sum+=R
        else:
            H.append("s")
            sum+=S
    for i in range(K,N):
        if T[i]=="r" and H[i-K]=="p":
            H.append("r")
        elif T[i]=="r":
            H.append("p")
            sum+=P
        elif T[i]=="s" and H[i-K]=="r":
            H.append("s")
        elif T[i]=="s":
            H.append("r")
            sum+=R
        elif T[i]=="p" and H[i-K]=="s":
            H.append("p")
        elif T[i]=="p":
            H.append("s")
            sum+=S
print(sum)

Submission status: Wrong Answer

Solution code:
import copy

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

#高橋くんが出す手 r=0,s=1,p=2
DP = [[0]*N for i in range(3)]
DP[0][0] = R if T[0] == 's' else 0
DP[1][0] = S if T[0] == 'p' else 0
DP[2][0] = P if T[0] == 'r' else 0

choices = []

for i in range(1,N):
    if T[i] == 'r':
        r,s,p = 0,0,P
    elif T[i] == 's':
        r,s,p = R,0,0
    else:
        r,s,p = 0,S,0

    lst = [DP[0][i-1],DP[1][i-1],DP[2][i-1]]
    m = max(lst)
    idx = lst.index(m)
    choices.append(idx)
    
    if i < K:
        DP[0][i] = m+r
        DP[1][i] = m+s
        DP[2][i] = m+p

    else:
        DP[0][i] = m+r if choices[-K] != 0 else 0
        DP[1][i] = m+s if choices[-K] != 1 else 0
        DP[2][i] = m+p if choices[-K] != 2 else 0

print(max(DP[0][N-1],DP[1][N-1],DP[2][N-1]))

Submission status: Wrong Answer

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

prls = [0] * k
point = 0
for i in range(n):
    if i < k:
        if t[i] == "r":
            prls[i] = "p"
            point += p
        elif t[i] == "s":
            prls[i] = "r"
            point += r
        elif t[i] == "p":
            prls[i] = "s"
            point += s
    else:
        if t[i] == "r":
            if prls[i % k] == "p":
                if (i+k<n):
                    if (t[i+k]=="s"):
                        prls[i % k] = "s"
                    else:
                        prls[i % k] = "r"
                else:
                    prls[i % k] = "r"
                    
            else:
                prls[i % k] = "p"
                point += p
        elif t[i] == "s":
            if prls[i % k] == "r":
                if (i+k<n):
                    if (t[i+k]=="s"):
                        prls[i % k] = "p"
                    else:
                        prls[i % k] = "s"  
                else:
                    prls[i % k] = "s"  
            else:
                prls[i % k] = "r"
                point += r
        elif t[i] == "p":
            if prls[i % k] == "s":
                if (i+k<n):
                    if (t[i+k]=="s"):
                        prls[i % k] = "r"
                    else:
                        prls[i % k] = "p"  
                else:
                    prls[i % k] = "p"  
            else:
                prls[i % k] = "s"
                point += s
print(point)

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"}
a = {"r": "s", "s": "p", "p": "r"}
janken = []

score = 0
for i in range(N):
  if len(janken) < K:
    score += d[T[i]]
    janken.append(D[T[i]])
  elif D[T[i]] != janken[-K]:
    score += d[T[i]]
    janken.append(D[T[i]])
  elif T[i] != janken[-K]:
    janken.append(T[i])
  else:
    janken.append(a[T[i]])
    
print(score)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,k = [int(x) for x in stdin.readline().rstrip().split()]
r,s,p = [int(x) for x in stdin.readline().rstrip().split()]
t = stdin.readline().rstrip()
r,s,p = p,r,s
rsp = [0] * 3

if r >= s and r >= p:
    rsp[0] = 'r'
elif r >= s and r < p:
    rsp[1] = 'r'
elif r < s and r >= p:
    rsp[1] = 'r'
elif r < s and r < p:
    rsp[2] = 'r'


if s >= r and s >= p:
    rsp[0] = 's'
elif s >= r and s < p:
    rsp[1] = 's'
elif s < r and s >= p:
    rsp[1] = 's'
elif s < r and s < p:
    rsp[2] = 's'


if p >= s and p >= r:
    rsp[0] = 'p'
elif p >= s and p < r:
    rsp[1] = 'p'
elif p < s and p >= r:
    rsp[1] = 'p'
elif p < s and p < r:
    rsp[2] = 'p'
answer = 0
a = max(r,s,p)
c = min(r,s,p)
b = r+s+p -a-c
tk = t
t = [0] * n
for i in range(n):
    t[i] = tk[i]

for i in range(n):
    if i <= k-1:
        if t[i] == rsp[0]:
            answer += a
    else:
        if t[i] == rsp[0]:
            if t[i] == t[i-k]:
                t[i] = 'n'
            else:
                answer += a
for i in range(n):
    if i <= k-1:
        if t[i] == rsp[1]:
            answer += b
    else:
        if t[i] == rsp[1]:
            if t[i] == t[i-k]:
                t[i] = 'n'
            else:
                answer += b
for i in range(n):
    if i <= k-1:
        if t[i] == rsp[2]:
            answer += c
    else:
        if t[i] == rsp[2]:
            if t[i] == t[i-k]:
                t[i] = 'n'
            else:
                answer += c
print(answer)

Submission status: Wrong Answer

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

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()]
s = list(input())

ans = 0
for i in range(len(s)):
    if i+k<len(s) and s[i+k]==s[i]:
        s[i+k] = '.'
        continue
    if 'r'==s[i]:
        ans += r
    elif 's'==s[i]:
        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()
U = list()
before = ""
ans = 0

for i in range(len(T)):
    if i >= K:
        before = U[-K]
    if T[i] == "r":
        U.append("p")
    elif T[i] == "s":
        U.append("r")
    else:
        U.append("s")
    if before == U[i]:
        U[i] = T[i]

for i in range(len(T)):
    if T[i] == "r" and U[i] == "p":
        ans += P
    elif T[i] == "s" and U[i] == "r":
        ans += R
    elif T[i] == "p" and U[i] == "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 = str(input())
box = [0.1 for i in range(len(T))]
for i in range(len(T)):
    if T[i] == "r":
        if box[i-k] != p:
            box[i] = p
        else:
            box[i]=0
    elif T[i]=="s":
        if box[i-k] != r:
            box[i] = r
        else:
            box[i]=0
    else:
        if box[i-k] != s:
            box[i] = s
        else:
            box[i]=0
print(sum(box))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
d = {'p': S, 's': R, 'r': P}
flag = [0] * K
for n in range(N):
    q = n % K
    ans += d.get(T[n])
    if n >= K and T[n] == T[n - K] and n < N - K:
        flag[q] += 1
    elif (flag[q] != 0 and T[n] != T[n - K]) or n >= N - K:
        if n >= N - K and T[n] == T[n - K]:
            flag[q] += 1
        ans -= d.get(T[n - K]) * ((flag[q] + 1) // 2)
        flag[q] = 0
print(ans)