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

a=[[] for i in range(k)]

for i in range(n):
    a[i%k].append(T[i])

flg=0
score=0
for j in range(k):
    b=a[j]

    for l in range(len(b)):
        if l==0:
            if b[l]=='r':
                score+=p
            elif b[l]=='s':
                score+=r
            elif b[l]=='p':
                score+=s
        else:
            if b[l-1]==b[l] and flg==0:
                flg=1
                continue
            elif b[l-1]==b[l] and flg==1:
                if b[l]=='r':
                    score+=p
                elif b[l]=='s':
                    score+=r
                elif b[l]=='p':
                    score+=s
                flg=0
            elif b[l-1]!=b[l]:
                if b[l]=='r':
                    score+=p
                elif b[l]=='s':
                    score+=r
                elif b[l]=='p':
                    score+=s
                flg=0

print(score)

Submission status: Wrong Answer

Solution code:
def main():
    # r:ぐー,s:ちょき,p:ぱー
    # 相手のn回目の手についてn%Kの値によってグループ分け
    # 連続して同じ手を出せずに最高点を出す方法を知れば良い
    # 最後に全てを足し合わせる
    N,K = map(int, input().split())
    R,S,P = map(int, input().split())
    T = input()
    hands = [[] for i in range(K)]
    for i in range(N):
        hands[i%K].append(T[i])
    # 貪欲に前から勝てば良い
    ans = 0
    for i in range(K):
        point = 0
        for j in range(len(hands[i])):
            # 最初は必ず勝てる
            if j==0:
                if hands[i][j]=='r':
                    prev = 'p'
                    point += P
                elif hands[i][j]=='s':
                    prev = 'r'
                    point += R
                else:
                    prev = 's'
                    point += S
            else:
                if hands[i][j]=='r':
                    if prev=='p':
                        prev = 'r'
                    else:
                        prev = 'p'
                        point += P
                elif hands[i][j]=='s':
                    if prev=='r':
                        prev = 's'
                    else:
                        prev = 'r'
                        point += R
                else:
                    if prev=='s':
                        prev = 'p'
                    else:
                        prev = 's'
                        point += S
        ans += point
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()
# 相手の手に対して勝ったときの得点
rsp_dic = {"r":P,"s":R,"p":S}
# 相手の手に対して
rsp_dic2 = {0:P,1:R,2:S}
# 自分の手に対して勝てる相手の手
rsp_win = ["s","p","r"]
# 相手の手に対して勝てる自分の手
rsp_lose = {"r":2,"s":0,"p":1}

bestscore = [rsp_dic[S] for S in T]
bestscore = [0] + bestscore

# dp[i][0] i-Kでrockを出していないときの、iでの最大値
dp = [[0,0,0] for _ in range(N+1)]

acumscore = 0
for i in range(1,N+1):
    if i <= K:
        acumscore += bestscore[i-1] #一個前まで
        for rsp in [0,1,2]: #自分の出す手
            dp[i][rsp] = acumscore
            if T[i-1] == rsp_win[rsp]:
                dp[i][rsp] += rsp_dic[T[i-1]]
    else:
        acumscore += -bestscore[i-K] + bestscore[i-1]
        dp[i][0] = max(dp[i-K][1] + acumscore,
                       dp[i-K][2] + acumscore)
        dp[i][1] = max(dp[i-K][0] + acumscore,
                       dp[i-K][2] + acumscore)
        dp[i][2] = max(dp[i-K][0] + acumscore,
                       dp[i-K][1] + acumscore)
        dp[i][rsp_lose[T[i-1]]] += rsp_dic[T[i-1]]
print(max(dp[N]))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
    if t[k+i] == t[i]:
        t[k+i] == 0
x = t.count("r")*p+ t.count("s")*r+ t.count("p")*s
print(x)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
    if t[i+k] == t[i]:
        t[i+k] == 0
x = t.count("r")*p+t.count("s")*r+t.count("p")*s
print(x)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
    if t[i+k] == t[i]:
        t[i+k] == 0
x = t.count("r")*p+t.count("S")*r+t.count("p")*s
print(x)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
T = input()
dic = {"P":p,"R":r,"S":s}
dp = [0]*(n+1)
te = [0]*(n+1)
for i in range(n):
    if T[i] == "r":
        te[i] = "P"
    elif T[i] == "p":
        te[i] ="S"
    elif T[i] == "s":
        te[i] = "R"
for i in range(n):
    if i-k < 0:
        if T[i] == "r":
            dp[i] =dic["P"]
            te[i] = "P"
        elif T[i] == "s":
            dp[i] = dic["R"]
            te[i] = "R"
        elif T[i] == "p":
            dp[i] = dic["S"]
            te[i] = "S"
    elif i-k >= 0:
        if te[i] == te[i-k]:
            if T[i-k] == "r" and te[i-k] == "P":
                dp[i] = 0
                te[i] = "R"
            elif T[i-k] == "r" and te[i-k] == "R":
                dp[i] = dic["P"]
                te[i] = "P"
            if T[i-k] == "p" and te[i-k] == "S":
                dp[i] = 0
                te[i] = "P"
            elif T[i-k] == "p" and te[i-k] == "P":
                dp[i] = dic["S"]
                te[i] = "S"
            if T[i-k] == "s" and te[i-k] == "R":
                dp[i] = 0
                te[i] = "S"
            elif T[i-k] == "s" and te[i-k] == "S":
                dp[i] = dic["R"]
                te[i] = "R"
        else:
            if T[i] == "r":
                dp[i] =dic["P"]
                te[i] = "P"
            elif T[i] == "s":
                dp[i] = dic["R"]
                te[i] = "R"
            elif T[i] == "p":
                dp[i] = dic["S"]
                te[i] = "S"
print(sum(dp))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
lis = ['' for _ in range(len(t))]
ans = 0

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

    
  elif t[j] == 's' and lis[j-k] != 'r':
    ans+=r
    lis[j] = 'r'

  elif t[j] == 's' and lis[j-k] == 'r':
    lis[j] = 's'

    
  elif t[j] == 'r' and lis[j-k] != 'p':
    ans+=p
    lis[j] = 'p'

  elif t[j] == 'r' and lis[j-k] == 'p':
    lis[j] = 'r'
      

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
lis = ['' for _ in range(len(t))]
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
T = input()
dic = {"P":p,"R":r,"S":s}
dp = [0]*(n+1)
te = [0]*(n+1)
for i in range(n):
    if T[i] == "r":
        te[i] = "P"
    elif T[i] == "p":
        te[i] ="S"
    elif T[i] == "s":
        te[i] = "R"
for i in range(n):
    if i-k < 0:
        if T[i] == "r":
            dp[i] =dic["P"]
            te[i] = "P"
        elif T[i] == "s":
            dp[i] = dic["R"]
            te[i] = "R"
        elif T[i] == "p":
            dp[i] = dic["S"]
            te[i] = "S"
    elif i-k >= 0:
        if te[i] == te[i-k]:
            if T[i-k] == "r" and te[i-k] == "P":
                dp[i] = 0
                te[i] = "R"
            elif T[i-k] == "r" and te[i-k] == "R":
                dp[i] = 0
                te[i] = "P"
            if T[i-k] == "p" and te[i-k] == "S":
                dp[i] = 0
                te[i] = "P"
            elif T[i-k] == "p" and te[i-k] == "P":
                dp[i] = 0
                te[i] = "S"
            if T[i-k] == "s" and te[i-k] == "R":
                dp[i] = 0
                te[i] = "S"
            elif T[i-k] == "s" and te[i-k] == "S":
                dp[i] = 0
                te[i] = "R"
        else:
            if T[i] == "r":
                dp[i] =dic["P"]
                te[i] = "P"
            elif T[i] == "s":
                dp[i] = dic["R"]
                te[i] = "R"
            elif T[i] == "p":
                dp[i] = dic["S"]
                te[i] = "S"
print(sum(dp))

Submission status: Wrong Answer

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

for i in range(k):
    for j in t[i::k]:
        if j != pre:
            if j == "s":
                ans += s
            elif j == "p":
                ans += p
            else:
                ans += r
            pre = j
        else:
            pre = "0"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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


history = [-1 for i in range(N + 1)]
ans = 0
for i in range(len(T)):
    c = T[i]
    if c == 'r':
        if i < K:
            ans += P
            history[i] = 2
        else:
            if history[i - K] == 2:
                if i + K < len(T) and T[i + K] == 's':
                    history[i] = 1
                else:
                    history[i] = 0
            else:
                ans += P
                history[i] = 2
    if c == 's':
        if i < K:
            ans += R
            history[i] = 0
        else:
            if history[i - K] == 0:
                if i + K < len(T) and T[i + K] == 's':
                    history[i] = 2
                else:
                    history[i] = 1
            else:
                ans += R
                history[i] = 0
    if c == 'p':
        if i < K:
            ans += S
            history[i] = 1
        else:
            if history[i - K] == 1:
                if i + K < len(T) and T[i + K] == 's':
                    history[i] = 2
                else:
                    history[i] = 0
            else:
                ans += S
                history[i] = 1
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
hand_list = ""

for i in range(N):
    if i >= K and win_hand[T[i]] == hand_list[i-K]:
        hand_list += T[i]
    else:
        ans += point[win_hand[T[i]]]
        hand_list += win_hand[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()

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

ans = 0
hand_list = ""

for i in range(N):
    if i >= K:
        not_hand = hand_list[i-K]
    else:
        not_hand = ""

    opponent = T[i]
    if win_hand[opponent] == not_hand:
        hand_list += opponent
    else:
        ans += point[win_hand[opponent]]
        hand_list += win_hand[opponent]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    r,s,p=map(int, input().split())
    t=input()
    def kachip(te):
        if te=='r':
            return p
        elif te=='s':
            return r
        else:
            return s
    def kachite(te):
        if te == 'r':
            return 'p'
        elif te == 's':
            return 'r'
        else:
            return 's'

    check=[0]*k # 出した手
    ans=0
    for i in range(n):
        point=kachip(t[i])
        te=kachite(t[i])
        if check[i%k]==te:
            check[i%k]=t[i]
        else:
            ans+=point
            check[i%k]=te
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    r,s,p=map(int, input().split())
    t=input()
    def kachip(te):
        if te=='r':
            return p
        elif te=='s':
            return r
        else:
            return s
    def kachite(te):
        if te == 'r':
            return 'p'
        elif te == 's':
            return 'r'
        else:
            return 's'

    check=[0]*k # 出した手
    ans=0
    for i in range(n):
        x=kachip(t[i])
        if check[i%k]==kachite(t[i]):
            check[i%k]=t[i]
        else:
            ans+=x
            check[i%k]=kachite(t[i])
    print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
s,p,r=map(int,input().split())
t=input()
a=0
for i in range(k):
    d=1
    for j in range(i,n-k,k):
        if t[j]==t[j+k]:
            d+=1
        else:
            a-=(-d//2)*eval(t[j])
            d=1
    a-=(-d//2)*eval(t[j+k])
print(a)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    r,s,p=map(int, input().split())
    t=input()
    def kachi(te):
        if te=='r':
            return p
        elif te=='s':
            return r
        else:
            return s

    check=[0]*k # 出した手
    ans=0
    for i in range(n):
        x=kachi(t[i])
        if check[i%k]==x:
            check[i%k]=t[i]
        else:
            ans+=kachi(t[i])
            check[i%k]=x
    print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
s,p,r=map(int,input().split())
t=input()
a=0
for i in range(k):
    d=1
    for j in range(i,n-k,k):
        #print(t[j])
        if t[j]==t[j+k]:
            d+=1
        else:
            a-=(-d//2)*eval(t[j])
            #print(d,t[j],a)
            d=1
    a-=(-d//2)*eval(t[j+k])
    #print(t[j+k],d,a)
print(a)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = list(input())
    score = {"r": p, "s": r, "p": s}
    answer = 0
    for i in range(n):
        if i < k:
            answer += score[t[i]]
        elif i + k < n:
            if t[i][0] != t[i + k][0] or "*" in t[i]:
                answer += score[t[i][0]]
            else:
                t[i + k] = t[i + k] + "*"
        else:
            answer += score[t[i][0]]
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

hand = {"r":p,"s":r,"p":s}
ans = 0
for i in range(n):
    if a[i-k] == a[i] and i-k >= 0:
        ans += 0
    else:
        ans += hand[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()

ans = 0
pre = [0]*n
for i in range(n):
    if i <=k-1:
        
        if t[i] == "r":
            ans += p
            pre[i] = "p"
        elif t[i] == "s":
            ans += r
            pre[i] = "r"
        elif t[i] == "p":
            ans += s
            pre[i] = "s"
        #print(ans)
    elif i >=k:
        if t[i] == "r":
            if pre[i-k] =="p":
                ans +=0
                pre[i] = "r"
                
            else:
                if pre[i-k] !="p":
                    ans +=p
                    pre[i] = "p"
                    
        if t[i] == "s":
            if pre[i-k] =="r":
                ans +=0
                pre[i] = "s"
            else:
                if pre[i-k] !="r":
                    ans +=r
                    pre[i] = "r"
        if t[i] == "p":
            if pre[i-k] =="s":
                ans +=0
                pre[i] = "p"
            else:
                if pre[i-k] !="s":
                    ans +=r
                    pre[i] = "s"
        
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a,b,c=map(int,input().split())
s=input()
l=['']*k
for i in range(n):
  l[i%k]+=s[i]
ans=0
d={'s':a,'p':b,'r':c}
for i in range(k):
  x=l[i]
  for j in range(len(x)//2):
    if x[2*j]==x[2*j+1]:
      ans+=d[x[2*j]]
    else:
      ans+=(d[x[2*j]]+d[x[2*j+1]])
  if len(x)%2==1:
    ans+=d[x[-1]]
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a,b,c=map(int,input().split())
s=input()
l=['a']*k
for i in range(n):
  l[i%k]+=s[i]
ans=0
d={'s':a,'p':b,'r':c}
for i in range(k):
  x=l[i]
  for j in range(len(x)-1):
    if x[j+1]==x[j]:
      ans+=d[x[j+1]]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    ans = 0
    mt = ""
    for i in range(N):
        if i - K >= 0:
            if mt[i-K] == win[T[i]][0]:
                mt += T[i]
            else:
                mt += win[T[i]][0]
                ans += win[T[i]][1]
        else:
            mt += win[T[i]][0]
            ans += win[T[i]][1]
    print(ans)


if __name__ == "__main__":
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    win = {"r": ("p", P), "s": ("r", R), "p": ("s", S)}
    T = input()
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N, K = geta(int)
    R, S, P = geta(int)
    T = gete()

    def winner(c):
        return (R, 0, 0) if c == "s" else (0, P, 0) if c == 'r' else (0, 0, S)

    def fn(s):
        print("deb", s)

        n = len(s)
        ret = 0
        dp = [[0] * 3 for _ in range(n)]

        dp[0] = winner(s[0])
        for i in range(1, n):
            w = winner(s[i])
            for j in range(3):
                dp[i][j - 2] = max(dp[i - 1][j - 1], dp[i - 1][j]) + w[j - 2]

        return (max(dp[n - 1]))

    print(sum(fn(T[i::K]) for i in range(K)))


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

# hash
point_dict = {"s": r, "p": s, "r": p}
 
cnt = 0
for i in range(len(t)):
    if i - k >= 0:
        if t[i - k] == t[i]:
          continue
    cnt += point_dict[t[i]]
print(cnt)

Submission status: Wrong Answer

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

cnt = 0
ans = []

for i in range(n):
  if i > k:
    if t[i] == 'r':
      if t[i-k] == 'p':
        ans.append('r')
      else:
        ans.append('p')
        cnt+=p
    elif t[i] == 's':
      if t[i-k] == 'r':
        ans.append('s')
      else:
        ans.append('r')
        cnt+=r
    elif t[i] == 'p':
      if t[i-k] == 's':
        ans.append('p')
      else:
        ans.append('s')
        cnt+=s
  else:
    if t[i] == 'r':
      ans.append('p')
      cnt+=p
    elif t[i] == 's':
      ans.append('r')
      cnt+=r
    elif t[i] == 'p':
      ans.append('s')
      cnt+=s
print(cnt)

Submission status: Wrong Answer

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

#ジャンケン
#勝利パターンでマックス
#k回前の値と判定

cnt = 0
ans = []

for i in range(n):
  if i > k:
    if t[i] == 'r':
      if t[i-k] == t[i]:
        ans.append('r')
        continue
      ans.append('p')
      cnt+=p
    elif t[i] == 's':
      if t[i-k] == t[i]:
        ans.append('s')
        continue
      ans.append('r')
      cnt+=r
    elif t[i] == 'p':
      if t[i-k] == t[i]:
        ans.append('p')
        continue
      ans.append('s')
      cnt+=s
  else:
    if t[i] == 'r':
      ans.append('p')
      cnt+=p
    elif t[i] == 's':
      ans.append('r')
      cnt+=r
    elif t[i] == 'p':
      ans.append('s')
      cnt+=s

print(cnt)

Submission status: Wrong Answer

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

ans=0

for j in range(len(T)):
    if j<=K:
        if T[j]=='r':
            ans+=P
        elif T[j]=='s':
            ans+=R
        else:
            ans+=S
    elif j>K and T[j]!=T[j-K]:
        if T[j]=='r':
            ans+=P
        elif T[j]=='s':
            ans+=R
        else:
            ans+=S
    else:
        T[j]=''
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
R,S,P =map(int,input().split())
T = list(input())
value= {'r':P,'s':R,'p':S}
ans = 0
pre = ''
#k個ごとのグループで考える
for i in range(k):
    num = i
    while num<n:
        if pre == T[num]:#同じ手だったら負けかあいこ．つまり0点カウント
            pre = ''
        else:
            pre = T[num]
            ans += value[pre]
        num += k
print(ans)

Submission status: Wrong Answer

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

wn = {'r': 'p', 's': 'r', 'p': 's'}
pt = {'r': P, 's': R, 'p': S}

ans = 0
t = [''] * len(s)
for i in range(len(s)):
    if i + 1 <= K:
        ans += pt[s[i]]
        t[i] = wn[s[i]]
    else:
        if wn[s[i]] != t[i-K]:
            ans += pt[s[i]]
            t[i] = wn[s[i]]
        else:
            t[i] = s[i]

print(ans)

Submission status: Wrong Answer

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

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

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


global memo
memo = defaultdict(int)


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

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

        # メモ化
        tmp = "".join([str(x) for x in li])

        if len(v) > 0:
            tmp = tmp + v[0]

            if memo[tmp] != 0:
                return memo[tmp]

        score = 0

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

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

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

        memo[tmp] = score

        return score
    return f(li, v)


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

print(sum(ans))

Submission status: Wrong Answer

Solution code:
# d
import numpy as np
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = np.array(list(input()))
t = np.where(t == 'r', p, t)
t = np.where(t == 's', r, t)
t = np.where(t == 'p', s, t)
t = t.astype(dtype='int64')

point = np.sum(t[:k])

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

print(point)

Submission status: Wrong Answer

Solution code:
# d
import numpy as np
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = np.array(list(input()))
t = np.where(t == 'r', p, t)
t = np.where(t == 's', r, t)
t = np.where(t == 'p', s, t)
t = t.astype(dtype='int64')
tt = t
point = 0
point += np.sum(t[:k])

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

print(point)

Submission status: Wrong Answer

Solution code:
# d
import numpy as np
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = np.array(list(input()))
t = np.where(t == 'r', p, t)
t = np.where(t == 's', r, t)
t = np.where(t == 'p', s, t)
t = t.astype(dtype='int64')
tt = t
point = 0
point += np.sum(t[:k])

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

print(point)

Submission status: Wrong Answer

Solution code:
# d
import numpy as np
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = np.array(list(input()))
t = np.where(t == 'r', p, t)
t = np.where(t == 's', r, t)
t = np.where(t == 'p', s, t)
t = t.astype(dtype='int64')
tt = t
point = 0
point += np.sum(t[:k])

for i in range(k+1,n):
    if t[i] == t[i-k]:
        pass
    elif t[i] != t[i-k]:
        point += t[i]

print(point)

Submission status: Wrong Answer

Solution code:
# d
import numpy as np
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = np.array(list(input()))
t = np.where(t == 'r', p, t)
t = np.where(t == 's', r, t)
t = np.where(t == 'p', s, t)
t = t.astype(dtype='int64')
tt = t
for i in range(n-k):
    if t[i] == t[i+k]:
        tt[i+k] = 0
    elif t[i] != t[i+k]:
        pass
            
print(np.sum(tt))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(sum(result))

Submission status: Wrong Answer

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

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

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

print(sum(result))

Submission status: Wrong Answer

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

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

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