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: Accepted

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
f_l=[False]*K #Trueなら連続している

ans = 0
for i in range(N):
  if i<=K-1:
    if T[i]== "r":
      ans += P
    elif T[i]=="s":
      ans += R
    else:
      ans += S
    #print(i,ans)
  else:
    #print(i,f_l[i%K])
    if T[i]==T[i-K]:
      if f_l[i%K]==True: 
        f_l[i%K]=False
      else:
        f_l[i%K]=True
    else:
      f_l[i%K]=False
    if f_l[i%K]==False:
      if T[i]== "r":
        ans += P
      elif T[i]=="s":
        ans += R
      else:
        ans += S
    #print(i,ans)
print(ans)

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = input()
a = {"r": p, "s": r, "p": s}
b = {"r": "p", "s": "r", "p": "s"}

ans = 0
u = ""
for i in t:
    if len(u)<k:
        ans += a[i]
        u+=b[i]
    elif u[-k] == b[i]:
        u+="1"
        ans += 0
    else:
        ans += a[i]
        u += b[i]

print(ans)

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
R, S, P = lr()
T = list(sr())
answer = 0
for i, t in enumerate(T):
    if i >= K and t == T[i-K]:
        T[i] = '_'
        continue
    dic = {'r': P, 's': R, 'p': S}
    answer += dic[t]

print(answer)
# 51

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
for i in range(k):
    tmp=t[i::k]
    l=len(tmp)
    dp=[[0 for i in range(3)] for j in range(l+1)]
    for j in range(1,l+1):
        dp[j][0] = max(dp[j-1][1]+r,dp[j-1][2]+r) if tmp[j-1] == 's' else max(dp[j-1][1],dp[j-1][2])
        dp[j][1] = max(dp[j-1][0]+s,dp[j-1][2]+s) if tmp[j-1] == 'p' else max(dp[j-1][0],dp[j-1][2])
        dp[j][2] = max(dp[j-1][0]+p,dp[j-1][1]+p) if tmp[j-1] == 'r' else max(dp[j-1][0],dp[j-1][1])
    ans+=max(dp[-1])
print(ans)

Submission status: Accepted

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

for i in range(k):
  ST = T[i::k]
  l = len(ST)
  dp = [[0 for i in range(3)] for j in range(l+1)]
  for j in range(1,l+1):
    dp[j][0] = max(dp[j-1][1]+r,dp[j-1][2]+r) if ST[j-1] == 's' else max(dp[j-1][1],dp[j-1][2])
    dp[j][1] = max(dp[j-1][0]+s,dp[j-1][2]+s) if ST[j-1] == 'p' else max(dp[j-1][0],dp[j-1][2])
    dp[j][2] = max(dp[j-1][0]+p,dp[j-1][1]+p) if ST[j-1] == 'r' else max(dp[j-1][0],dp[j-1][1])
  ret+=max(dp[-1])
print(ret)

Submission status: Accepted

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] == t[i+k]:
    t[i+k] = 0

print(sum([t.count("r")*p, t.count("s")*r, t.count("p")*s]))

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
V = {'r':P, 's':R, 'p':S}
ans = 0

for i in range(K):
    check = T[i]
    ans += V[check]
    while True:
        i += K
        if i >= N:
            break
        if check == T[i]:
            check = '-1'
        else:
            ans += V[T[i]]
            check = T[i]
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
rp, sp, pp = map(int, input().split())
t = list(input())
point = 0
pdic = {"r":pp, "s": rp, "p":sp}
dic = {"r":[0], "s":[0], "p":[0]}
for l in range(1,k+1,1):
    prev = None
    for m in range(0,(n+1)//k+1,1):
        if k*m+l <= n:    
            if t[k*m+l-1] == prev:
                dic[t[k*m+l-1]][-1] += 1
            else:
                dic[t[k*m+l-1]].append(1)
            prev=t[k*m+l-1]
# print(dic)
for key, value in dic.items():
    for v in value:
        if v == 1:
            point+=v*pdic[key]
        else:
            point+=(v//2+v%2)*pdic[key]
#     print("key....{},point.....{}".format(key, point))
print(point)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    point = 0
    p = {'r':P, 's':R, 'p':S}
    taka = [True] * K

    for i in range(K):
        point += p.get(T[i])
    
    for i in range(K, N):
        if T[i] == T[i-K]:
            if taka[i-K]:
                taka.append(False)
            else :
                point += p.get(T[i])
                taka.append(True)
        else:
            point += p.get(T[i])
            taka.append(True)

    print(point)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#python3

def main():
    n, k = map(int, input().split())
    R, S, P = map(int, input().split())
    t = input()

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

    ans = 0
    for i in range(k):
        div = t[i::k] + 'x'
        seq = 1
        for j in range(len(div)-1):
            winHandPoint = win[div[j]]
            if div[j] == div[j+1]: 
                seq += 1 
            else:
                ans += (seq+1)//2 * winHandPoint
                seq = 1
    print(ans) 
main()

Submission status: Accepted

Solution code:
from collections import deque
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
d = deque([0]*k)
popleft = d.popleft
append = d.append
result = 0
temp = ""
for el in t:
    if el == "r":
        if popleft() != "p":
            result += p
            append("p")
        else:
            append("n")
    elif el == "s":
        if popleft() != "r":
            result += r
            append("r")
        else:
            append("n")
    else:
        if popleft() != "s":
            result += s
            append("s")
        else:
            append("n")
print(result)

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split())
    r,s,p=map(int,input().split())
    t=list(input().strip())
    ans=0
    for i in range(n):
        if i>=k:
            if t[i]==t[i-k]:
                t[i]='x'
        if t[i]=='r':
            ans+=p
        elif t[i]=='s':
            ans+=r
        elif t[i]=='p':
            ans+=s
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

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

for i in range(len(t) - k):
    if t[i] == t[i+k]:
        t[i+k] = '-'


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


print(score)

Submission status: Accepted

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

score = 0
for i in range(N):
  if i >= K and T[i] == T[i-K]:
    T[i] = 'x'
  elif T[i] == 'r':
    score += P
  elif T[i] == 's':
    score += R
  elif T[i] == 'p':
    score += S
print(score)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc149/submissions/9213312

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

win_pt = {"r": P, "s": R, "p": S}
pt = [0] * N

for i, t in enumerate(T):
    if i < K:
        pt[i] = win_pt[t]
    elif i >= K and (T[i - K] != T[i] or pt[i - K] == 0):
        pt[i] = win_pt[t]
print(sum(pt))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
D = {"r":P,"s":R,"p":S}
T = input().strip()
C = {i:[] for i in range(K)}
for i in range(N):
    C[i%K].append(T[i])
cnt = 0
for i in range(K):
    num = 1
    for j in range(1,len(C[i])):
        if C[i][j]==C[i][j-1]:
            num += 1
        else:
            cnt += D[C[i][j-1]]*((num+1)//2)
            num = 1
    cnt += D[C[i][-1]]*((num+1)//2)
print(cnt)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, k = MAP()
rsp = LIST()
arr = ['s', 'p', 'r']
t = STR()
res = [-1 for _ in range(n)]
for i in reversed(range(n)):
    res[i] = arr.index(t[i])
    if i + k < n and res[i + k] == res[i]:
        res[i] = -1
ans = 0
for i in range(n):
    ans += rsp[res[i]] if res[i] > -1 else 0
print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
cpu = [c for c in input()]
point = 0
henkan = {'r':0, 's':1, 'p':2}
haiten = [P, R, S]
for i in range(K):
    count = 1
    j = i
    while j < N - K:
        if cpu[j] == cpu[j + K]:
            count += 1
        else:
            point += haiten[henkan[cpu[j]]] * ((count + 1) // 2)
            count = 1
        j += K
    point += haiten[henkan[cpu[j]]] * ((count + 1) // 2)
print(point)

Submission status: Accepted

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]=""
ans=T.count("r")*P+T.count("s")*R+T.count("p")*S
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(K):
    if T[i]=='r':ans += P
    elif T[i]=='s':ans += R
    else: ans+= S

for i in range(K, N):
    if T[i]=='r':
        if T[i-K]!='r':ans += P
        else:T[i] = '0'
    elif T[i]=='s':
        if T[i-K]!='s':ans += R
        else:T[i] = '0'
    else:
        if T[i-K]!='p': ans+= S
        else:T[i] = '0'
print(ans)

Submission status: Accepted

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

def win(enemy):
    if enemy == 'r':
        return 'p'
    elif enemy == 'p':
        return 's'
    else:
        return 'r'
def point(hand):
    if hand == 'r':
        return R
    elif hand == 'p':
        return P
    else:
        return S

ans = 0
buf = []
for i in range(N):
    t = T[i]
    hand = win(t)
    if i-K < 0 or buf[i-K] != hand:
        buf.append(hand)
        ans += point(hand)
    else:
        buf.append('')

print(ans)

Submission status: Accepted

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] == t[i+k]:
    t[i+k] = 0

print(sum([t.count("r")*p, t.count("s")*r, t.count("p")*s]))

Submission status: Accepted

Solution code:
def max_score(str, r, s, p):
    run_str, run_length, max_score = str[0], 1, 0
    score = {'r': p, 's': r, 'p': s}
    for next in range(1, len(str)):
        if run_str == str[next]:
            run_length += 1
        else:
            max_score += -(-run_length // 2) * score[run_str]
            run_str = str[next]
            run_length = 1
    max_score += -(-run_length // 2) * score[run_str]
    return max_score
    
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
sum_max_score = 0
for i in range(k):
    sum_max_score += max_score(t[i::k], r, s, p)
print(sum_max_score)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
ans=0
#print(T)
for i in range(K):
    if T[i]=="r":
        ans+=P
    if T[i]=="s":
        ans+=R
    elif T[i]=="p":
        ans+=S

for i in range(K,N):
    if T[i]!=T[i-K]:
        if T[i]=="r":
            ans+=P
        elif T[i]=="s":
            ans+=R
        elif T[i]=="p":
            ans+=S
    else:
        T[i]=""
print(ans)

Submission status: Accepted

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    R, S, P = il()
    T = list(iss())

    ret = 0
    bk = ['n']*N
    for n in range(N):
        t = T[n]
        tmp = 0
        if t == 'r' and bk[n-K] != 'p':
            tmp = P
            bk[n] = 'p'
        elif t == 's' and bk[n-K] != 'r':
            tmp = R
            bk[n] = 'r'
        elif t == 'p' and bk[n-K] != 's':
            tmp = S
            bk[n] = 's'

        ret += tmp

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
for i in range(k):
  x=i
  cnt=0
  while x+k<n:
    if t[x]==t[x+k]:
      cnt+=1
    else:
      if t[x]=='r':
        ans+=p*(cnt//2+1)
      elif t[x]=='s':
        ans+=r*(cnt//2+1)
      else:
        ans+=s*(cnt//2+1)
      cnt=0
    x+=k
  if t[x]=='r':
    ans+=p*(cnt//2+1)
  elif t[x]=='s':
    ans+=r*(cnt//2+1)
  else:
    ans+=s*(cnt//2+1)
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
res=0
for i in range(K):
    st=T[i::K]
    le=len(st)
    dp=[[0,0,0] for i in range(le+1)]
    for j in range(1,le+1):
        dp[j][0]=max(dp[j-1][1]+R,dp[j-1][2]+R) if st[j-1]=='s' else max(dp[j-1][1],dp[j-1][2])
        dp[j][1]=max(dp[j-1][0]+S,dp[j-1][2]+S) if st[j-1]=='p' else max(dp[j-1][0],dp[j-1][2])
        dp[j][2]=max(dp[j-1][0]+P,dp[j-1][1]+P)  if st[j-1]=='r' else max(dp[j-1][0],dp[j-1][1])
    res+=max(dp[le])
print(res)

Submission status: Accepted

Solution code:
#abc149d
n,k=map(int,raw_input().split())
r,s,p=map(int,raw_input().split())
t=map(str,raw_input().rstrip())
pt={'r':p,'s':r,'p':s,'':0}
res=0
for i in range(n):
 x=i-k
 if x>=0 and t[x]==t[i]:
  t[i]=''
 res+=pt[t[i]]
print res

Submission status: Accepted

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

for i in range(yu):
    if i <= k-1:
        if t[i] == "r":
            ans += p
        elif t[i] == "s":
            ans += r
        elif t[i] == "p":
            ans += s
    elif t[i] == t[i-k]:
        t = t[:i] + "x" + t[i+1:]
    else:
        if t[i] == "r":
            ans += p
        elif t[i] == "s":
            ans += r
        elif t[i] == "p":
            ans += s
print(ans)

Submission status: Accepted

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

for i in range(n-k):
    if t_list[i] == t_list[i+k]:
        t_list[i+k] = "_"
        
result = t_list.count('r')*p + t_list.count('p')*s + t_list.count('s')*r

print(result)

Submission status: Accepted

Solution code:
def win(x):
    if x == "r":
        return p
    elif x == "s":
        return r
    else:
        return s


n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = input()

flags = [False] * n
ans = 0
for i in range(n):
    if i - k >= 0 and t[i - k] == t[i] and not flags[i - k]:
        flags[i] = True
        continue
    ans += win(t[i])
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
R, S, P = map(int, input().split())
a = input()
flag = [False] * n


def win(x):
    if x == "r":
        return P
    elif x == "s":
        return R
    else:
        return S


su = 0
for i in range(n):
    if i - k >= 0 and a[i-k] == a[i] and not flag[i-k]:
        flag[i] = True
        continue
    else:
        su += win(a[i])
print(su)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
n,k=f()
d={c:v for c,v in zip('spr',f())}
t=input()
l=[1]*n
a=0
for i in range(n):
  if l[i-k] or t[i]!=t[i-k]:
    a+=d[t[i]]; l[i]=0
print(a)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
RSP=list(map(int,(input().split())))
T=input()
ans=0
cand="RSP"
def win(x):
    if x=="r":
        return 2
    elif x=="p":
        return 1
    elif x=="s":
        return 0
    else:
        return "error"
ans=0
H=""
for i in range(N):
    if i<K:
        ans+=RSP[win(T[i])]
    elif win(T[i])!=win(T[i-K]):
        ans+=RSP[win(T[i])]
    else:
        T=T[:i]+"x"+T[i+1:]

print(ans)

Submission status: Accepted

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

score = 0
score_dict = {"r": R, "s": S, "p": P}
restriction_list = list("" for _ in range(K))

for i in range(N):
    prediction = t[i]
    restriction = restriction_list[i % K]
    if prediction == restriction:
        restriction_list[i % K] = ""
        continue
    else:
        score += score_dict[prediction]
        restriction_list[i % K] = prediction

print(score)

Submission status: Accepted

Solution code:
import numpy as np
n, k = list(map(int, input().split()))
r, s ,p = list(map(int, input().split()))
e = input()

e_list = np.array(list(map(int, list(e.replace("r", "0").replace("s", "1").replace("p", "2")))))
score_map = [p, r, s]

ans = 0
for i in range(k):
    e = list(e_list[i:][::k])
    now = -2
    score = 0
    for ee in e:
        if ee == now:
            now = -1
        else:
            now = ee
            score += score_map[now]
    ans += score
#     print(e, ans)

print(ans)

Submission status: Accepted

Solution code:
line = list(input().split(" "))
n = int(line[0])
k = int(line[1])
line = list(input().split(" "))
r = int(line[0])
s = int(line[1])
p = int(line[2])
line = list(input())
result = 0
dp = [[0,0,0]for i in range(n)]
for j in range(k):
    i = 1
    if line[j] == "r":
        dp[j] = [0,0,p]
    elif line[j] == "s":
        dp[j] = [r,0,0]
    else:
        dp[j] = [0,s,0]
    while True:
        m = k*i + j
        if m >= n:
            m -= k
            break
        if line[m] == "r":
            a = [0,0,p]
        elif line[m] == "s":
            a = [r,0,0]
        else:
            a = [0,s,0]
        dp[m][0] = max(dp[m-k][1]+a[0],dp[m-k][2]+a[0])
        dp[m][1] = max(dp[m-k][0]+a[1],dp[m-k][2]+a[1])
        dp[m][2] = max(dp[m-k][0]+a[2],dp[m-k][1]+a[2])
        i += 1
    result += max(dp[m][0],dp[m][1],dp[m][2])
print(result)

Submission status: Accepted

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

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

ans = 0

for i in range(n):
    if t[i] == a[i%k]:
        a[i%k] = "a"
    elif t[i] == "r":
        a[i%k] = "r"
        ans += r
    elif t[i] == "s":
        a[i%k] = "s"
        ans += s
    else:
        a[i%k] = "p"
        ans += p

print(ans)

Submission status: Accepted

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

ans = 0

a = -(-N//K)
r = N%K
T2 = T + 'x'*(K - r)

li = []
for i in range(K):
    st = ''
    for j in range(a):
        c = T2[j*K + i]
        if st == '':
            st += c
        elif st[0] == c:
            st += c
        else:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S
            st = c
        if j == a-1:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S

print(ans)

Submission status: Accepted

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

S = list(input())
T = [0]*n

for i in range(n):
    l = S[i]
    if(l == "r"):
        T[i] = p
    if(l == "s"):
        T[i] = r
    if(l == "p"):
        T[i] = s

sm = 0
#print(T)
for i in range(n):
    sm += T[i]
#print(sm)

for i in range(k,n):
    if(S[i-k]==S[i]):
        sm -= T[i]
        S[i] = "o"

#print(T)
print(sm)

Submission status: Accepted

Solution code:
import numpy as np

N,K = map(int,input().split())
Point = list(map(int,input().split()))
T = input()
T = "0" + T

dp = np.zeros(N+1,dtype='int')

win = {
    'r':2, # グーなのでパーで勝
    's':0, # チョキなのでグーで勝
    'p':1 # パーなのでチョキで勝
    }

for i in range(1,N+1):
    if i < K + 1:
        dp[i] = win[T[i]]
    else:
        if win[T[i]] != dp[ i - K ]:
            dp[i] = win[T[i]]
        else:
            # if (i + K) <= N:
            #     dp[i] = 3 - win[T[i + K]] - dp[ i - K ]
            # else:
            #     dp[i] = -1
            dp[i] = -1

# print(dp)
ans = 0

for j in range(1,N+1):
    if dp[j] >= 0:
        ans += Point[dp[j]]

print(ans)

Submission status: Accepted

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

def get_point(s):
  if s == "r":
    return P
  elif s == "s":
    return R
  elif s == "p":
    return S

ans = 0
restricted = [False] * N
for i in range(N):
  if (i+1) <= K:
    ans += get_point(T[i])
  else:
    if T[i-K] == T[i]:
      if restricted[i-K]:
        ans += get_point(T[i])
      else:
        restricted[i] = True
    else:
      ans += get_point(T[i])

print(ans)

Submission status: Accepted

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

num = 0
ans = 0
li = [True]*n

for i in range(n):
    if t[i]=="r":
        num = P
    elif t[i]=="s":
        num = R
    else:
        num = S
    if i>=k and t[i]==t[i-k] and li[i-k]:
        li[i] = False
        num = 0
    ans += num

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
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())
point_dict = {"r":p,"s":r, "p":s}
t = input()
# ゲームの問題
# ジャンケンをNかいする
# Kかい前の手と同じ手を出すことはできない
# 事前に相手が出す手がわかっている時の得点の最大化
# for i in range(k): に対してi+k*j 番目での手を前からgreedyにう考える
# bit を立ててk個前と同じ手だった時に勝てる手を出していいかを管理
ans = 0
for i in range(k):
    bit = 1 # 勝てる手を出していい
    j =0
    ans += point_dict[t[i+k*j]]
    j += 1
    while i+k*j <= n-1:
        if t[i+k*j] != t[i+k*j-k]:
            ans += point_dict[t[i+k*j]]
            bit = 1
        elif (t[i+k*j] == t[i+k*j-k] and bit == 0):
            ans += point_dict[t[i+k*j]]
            #print(t[i+k*j])
            bit = 1
        else:
            bit = 0
        j += 1
        #print(ans,i,j)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def ptget(strings):
    if strings == "r":
        return p
    elif strings == "s":
        return r
    else:
        return s

dic = {}
point = 0
for i in range(len(t)):
    if i % k in dic:
        dic[i%k].append(t[i])
        if dic[i%k][len(dic[i%k])-2] == "n":
            point += ptget(t[i])
        elif dic[i%k][len(dic[i%k])-2] == dic[i%k][len(dic[i%k])-1]:
            dic[i%k][len(dic[i%k])-1] = "n"
        else:
            point += ptget(t[i])
    else:
        dic[i%k] = [t[i]]
        point += ptget(t[i])
print(point)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    rs, ss, ps = map(int, input().split())
    s = input()

    score = 0

    winlose_list = [1] * n

    for i in range(n):
        if i-k >= 0 and s[i-k] == s[i] and winlose_list[i-k] == 1:
            winlose_list[i] = 0
            continue
            # if s[i] == 'r':
            #     score += rs
            # elif s[i] == 's':
            #     score += ss
            # elif s[i] == 'p':
            #     score += ps
            # winlose_list[i] = 0
            # print('aiko',i,s[i],score)
        else:
            if s[i] == 'r':
                score += ps
            elif s[i] == 's':
                score += rs
            elif s[i] == 'p':
                score += ss
            # print('Win',i,s[i],score)
            
    print(score)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Re = [False for _ in range(N)]
#Re[i]:i回目で勝った

def plus(t):
    if t == "r":
        return P
    elif t == "s":
        return R
    else:
        return S

ans = 0
for i in range(K):
    ans += plus(T[i])
    Re[i] = True

for i in range(K,N):
    if T[i] != T[i-K] or not Re[i-K]:
        ans += plus(T[i])
        Re[i] = True

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
ans=0
for i in range(K):
    L=T[i::K]
    l=len(L)
    rest='x'
    for k in range(l):
        c='p' if L[k]=='r' else 'r' if L[k]=='s' else 's'
        if(c!=rest):
            rest=c
            ans+=P if c=='p' else S if c=='s' else R
        else:
            rest='x'
print(ans)