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:


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

    m = []
    score = 0
    for i in range(n):
        if i - k >= 0:
            rest = m[-k]
        else:
            rest = None
        
        if t[i] == 'r':
            if rest == 'p':
                if i + k >= n:
                    # なんでもよい
                    m.append('r')
                else:
                    if t[i + k] == 's':
                        # k個先がsの場合、ここでrは出したくない
                        m.append('s')
                    else:
                        # k個先がpの場合、ここでsは出したくない
                        # k個先がrの場合、pじゃなければなんでもよい
                        m.append('r')
            else:
                m.append('p')
                score += p

        if t[i] == 'p':
            if rest == 's':
                # k個先を考える
                if i + k >= n:
                    # なんでもよい
                    m.append('r')
                else:
                    if t[i + k] == 'r':
                        # k個先がrの場合、ここでpは出したくない
                        m.append('r')
                    else:
                        # k個先がpの場合、sでなければなんでもよい
                        # k個先がsの場合、ここでrは出したくない
                        m.append('p')
            else:
                m.append('s')
                score += s

        if t[i] == 's':
            if rest == 'r':
                # k個先を考える
                if i + k >= n:
                    # なんでもよい
                    m.append('r')
                else:
                    if t[i + k] == 'r':
                        # k個先がrの場合、ここでpは出したくない
                        m.append('s')
                    else:
                        # k個先がpの場合、ここでsは出したくない
                        # k個先がsの場合、rじゃなければなんでもよい
                        m.append('p')
            else:
                m.append('r')
                score += r
        

    print(score)


if __name__ == "__main__":
    submit()

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(N):
    if i >= K:
        if T[i] == T[i-K]:
            T[i] = 'd'
    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=list(input())
dic={"r":p,"s":r,"p":s}
ans=0

for i in range(k):
    ans+=dic[t[i]]
for i in range(k,n):
    if t[i] != t[i-k]:
        ans+=dic[t[i]]
    else:
        try:
            if t[i] == t[i+k]:
                t[i] = "0"
        except:
            pass
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
L = [[] for i in range(k)]
for i in range(n):
    L[i%k].append(t[i])
ans = 0
for i in range(k):
    if L[i][0] == 's':
        ans += r
    elif L[i][0] == 'p':
        ans += s
    else:
        ans += p
    lose = False
    for j in range(1,len(L[i])):
        if L[i][j] != L[i][j-1]:
            lose = False
            if L[i][j] == 's':
                ans += r
            elif L[i][j] == 'p':
                ans += s
            else:
                ans += p
        elif L[i][j] == L[i][j-1]:
            if lose == True:
                if L[i][j] == 's':
                    ans += r
                elif L[i][j] == 'p':
                    ans += s
                else:
                    ans += p
                lose = False
            else:
                lose = True
print(ans)

Submission status: Accepted

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

def w(z):
    if z=="r":
        return p
    if z=="s":
        return r
    else:
        return s

ans = 0
li = [0]*len(t)
for i in range(len(t)):
    if i+k<len(t):
        if li[i]==1:
            continue
        if t[i]==t[i+k]: 
            ans += w(t[i])
            li[i+k] = 1
        else:
            ans += w(t[i])
    else:
        if li[i]==0:
            ans+=w(t[i])
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(len(t)):
    if i < k:
        if t[i] == "r":
            ans += p
        elif t[i] == "s":
            ans += r
        else:
            ans += s
    else:
        if t[i-k] == t[i]:
            t = t[:i]+"a"+t[i+1:]
        else:
            if t[i] == "r":
                ans += p
            elif t[i] == "s":
                ans += r
            else:
                ans += s
print(ans)

Submission status: Accepted

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

score = {"R":R,"P":P,"S":S}
def battle(user, box):
  d ={"S":0,"R":1,"P":2,
      "s":-1,"r":-2,"p":0}
  if (d[user] + d[box])%3 == 0:
    return score[user]
  else:
    return 0

for idx, teki in enumerate(T):
  for usr in "RPS":
  	dp[(idx,usr)] = max([
      dp[(idx-K,prev)]+battle(usr,teki) for prev in ("RPS".replace(usr,"")) 
    ])
    
print(sum ([max([dp[(N-r-1,te)] for te in "RPS"]) for r in range(K)]))

Submission status: Accepted

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

win={'r':'p','s':'r','p':'s'}
point={'r':R,'s':S,'p':P}
hand=['']*N
ans=0

for i in range(K):
    w=win[T[i]]
    ans+=point[w]
    hand[i]=w

for i in range(K,N):
    w=win[T[i]]
    if w==hand[i-K]:
        continue
    ans+=point[w]
    hand[i]=w
    
print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

ans = 0

wins = [False] * K

for i in range(N):
    if not wins[i % K] or T[i] != T[i - K]:
        ans += v_hand[T[i]]
        wins[i % K] = True
    else:
        wins[i % K] = False
        
print(ans)

Submission status: Accepted

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

score = [0] * n
for i in range(n):
    if i-k < 0:
        score[i] = table[t[i]]
        continue
    if t[i-k] == t[i] and score[i-k] != 0:
        score[i] = 0
    else:
        score[i] = table[t[i]]

print(sum(score))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def iip():
    return [int(i) for i in input().split()]

N, K = iip()
R, S, P = iip()
T = input()

point = 0
win = []
wp = {
    "r":P,
    "s":R,
    "p":S
}

for i in range(N):
    if i >= K and win[i-K] == T[i]:
        win.append(False)
    else:
        win.append(T[i])
        point += wp[T[i]]

#print(win)
print(point)

Submission status: Accepted

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

table = [-1 for i in range(len(t) + k)]
count = 0
for i in range(len(t)):
    if table[i-k] != -1 and table[i-k] == t[i]:
        continue
    elif t[i] == "r":
            count += p
            table[i] = "r"
    elif t[i] == "s":
            count += r
            table[i] = "s"
    elif t[i] == "p":
            count += s
            table[i] = "p"

print(count)

Submission status: Accepted

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

get_point = []
score = 0

for i in range(n):
    if t[i] == 'r':
        if i - k < 0 or get_point[i-k] != 'p':
            score += p
            get_point.append('p')
        else:
            get_point.append('e')
    elif t[i] == 's':
        if i - k < 0 or get_point[i-k] != 'r':
            score += r
            get_point.append('r')
        else:
            get_point.append('e')
    elif t[i] == 'p':
        if i - k < 0 or get_point[i-k] != 's':
            score += s
            get_point.append('s')
        else:
            get_point.append('e')

print(score)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
gu, choki, pa = map(int, input().split())
t = list(input())

total = 0
for i, v in enumerate(t):
    if i >= k and v == t[i-k]:
        t[i] = 'd'
    elif v == 'r':
        total += pa
    elif v == 's':
        total += gu
    else:
        total += choki
print(total)

Submission status: Accepted

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

points = 0
for i in range(N):
  if T[i]=="r":
    if i-K < 0 or T[i]!=T[i-K]:
      points+=P
    else:
      T[i]="x"
  elif T[i]=="s":
    if i-K < 0 or T[i]!=T[i-K]:
      points+=R
    else:
      T[i]="x"
  else:
    if i-K < 0 or T[i]!=T[i-K]:
      points+=S
    else:
      T[i]="x"
print(points)

Submission status: Accepted

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

ans=0
win=[0]*n
for i in range(len(t)):
    if i-k>=0 and win[i-k] == 1 and t[i]==t[i-k]:
        pass
    else:
        if t[i] == "r":
          ans+=p
        if t[i] == "s":
            ans+=r
        if t[i] == "p":
            ans+=s
        win[i]=1

print(ans)

Submission status: Accepted

Solution code:
def sol(score,hand):
    if hand=="r":
        return score["p"]
    elif hand=="p":
        return score["s"]
    elif hand=="s":
        return score["r"]
    return 0
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
win=""
for num,val in enumerate(t):
    if num<k or win[num-k]!=val:
        win+=val
    else:
        win+="n"
score={"r":r,"p":p,"s":s}
ans=0
for val in win:
    ans+=sol(score,val)

print(ans)

Submission status: Accepted

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

score = 0
hand_score = {'r': R, 's': S, 'p': P}
my_hand_dict = {'r': 'p', 's': 'r', 'p': 's'}
my_hand_list = list()
for i, hand in enumerate(T):
    if i < K:
        my_hand = my_hand_dict[hand]
        score += hand_score[my_hand]
        my_hand_list.append(my_hand)
    else:
        my_hand = my_hand_dict[hand]
        if my_hand != my_hand_list[i-K]:
            score += hand_score[my_hand]
            my_hand_list.append(my_hand)
        else:
            my_hand_list.append('0')

print(score)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
score = list(map(int, input().split()))
t_str = input()
hand = 'rsp'
t = []
for x in t_str:
    t.append(hand.index(x))

ans = 0
for r in range(k):
    d = [0] * 3
    for h in t[r::k]:
        dd = [0] * 3
        for i in range(3):
            for j in range(3):
                if i != j:
                    point = 0
                    if (j - h) % 3 == 2:
                        point = score[j]
                    dd[j] = max(dd[j], d[i] + point)
        d = dd
    ans += max(d)
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
win = {"r": "p", "s": "r", "p": "s"}
point = {"r": R, "s": S, "p": P}
taka = []
ans = 0
for i in range(N):
    if i >= K:
        if win[T[i]] == taka[i - K]:
            taka.append("*")
        else:
            taka.append(win[T[i]])
            ans += point[win[T[i]]]
    else:
        taka.append(win[T[i]])
        ans += point[win[T[i]]]
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
# r:"グー" p:"パー" s:"チョキ"
# p , s , r

pat = {"r":p, "p":s, "s":r, "":0}
hands = [""]*n
ans = 0
for i in range(n):
  if i < k or hands[i-k] != t[i]:
    hands[i] = t[i]
    ans += pat[t[i]]
    
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from fractions import gcd
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,K = inputIL()
R,S,P = inputIL()
T = list(inputS())

t = []
for i in range(K):
  t.append(T[i::K])
  
  
def get(s):
  if s=="r": return P
  if s=="s": return R
  if s=="p": return S
ans = 0

for l in t:
  skipped = 0
  for i in range(len(l)):
    if i == 0:
      ans += get(l[i])
    else:
      if l[i]!=l[i-1] or skipped == 1:
        ans += get(l[i])
        skipped = 0
      else:
        skipped = 1 

print(ans)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,k = mi()
ten = li()
t = input()
lis = ["a"]*n
for i in range(k,n):
    lis[i] = t[i-k]
ans = 0

for i in range(n):
    if t[i] == lis[i]:
        if i+k<n:
            lis[i+k] = "a"
        continue
    if t[i] == "s":
        ans += ten[0]
    elif t[i] == "p":
        ans += ten[1]
    else:
        ans += ten[2]
print(ans)

Submission status: Accepted

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

win = {"r":"p","s":"r","p":"s"}
point = {"r":r,"s":s,"p":p}

ans = []
sum = 0

for i in range(k):
    ans.append(win[t[i]])
    sum+=point[win[t[i]]]

for i in range(k,n):
    if win[t[i]] == ans[i - k]:
        ans.append(-1)
    else:
        ans.append(win[t[i]])
        sum+=point[win[t[i]]]
print(sum)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
T=[a for a in T]
answer=0
takahashi=[]
if N%K==0:
    number=(N/K-1)*K
else:
    number=(N//K)*K
for a in range(K):
    if T[a]=='r':
        answer+=P
        takahashi.append('p')
    elif T[a]=='s':
        answer+=R
        takahashi.append('r')
    else:
        answer+=S
        takahashi.append('s')
for a in range(K,int(number)):
    if T[a]=='r':
        if takahashi[a-K]=='p':
            if a+K<N:
                if T[a + K] == 's':
                    takahashi.append('s')
                else:
                    takahashi.append('r')
            else:
                pass
        else:
            answer+=P
            takahashi.append('p')
    elif T[a]=='s':
        if takahashi[a-K]=='r':
            if a+K<N:
                if T[a + K] == 'p':
                    takahashi.append('p')
                else:
                    takahashi.append('s')
            else:
                pass
        else:
            answer+=R
            takahashi.append('r')
    else:
        if takahashi[a-K]=='s':
            if a+K<N:
                if T[a + K] == 'r':
                    takahashi.append('r')
                else:
                    takahashi.append('p')
            else:
                pass
        else:
            answer+=S
            takahashi.append('s')
for a in range(int(number),N):
    if T[a]=='r':
        if takahashi[a-K]=='p':
            pass
        else:
            answer+=P
    elif T[a]=='s':
        if takahashi[a-K]=='r':
           pass
        else:
            answer+=R
    else:
        if takahashi[a-K]=='s':
            pass
        else:
            answer+=S
print(answer)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t_list = list(input())
towin = {"r": p, "s": r, "p": s}
ans = 0
for i in range(n):
    if i < k:
        ans += towin[t_list[i]]
    else:
        if t_list[i - k] == t_list[i]:
            t_list[i] = "-1"
        else:
            ans += towin[t_list[i]]
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
get_score=list(map(int,input().split()))
t=list(input())
dic={'r':0,'s':1,'p':2}

ans=0
for i in range(n):
    if t[i]=='D':continue
    if i+k<n and t[i]==t[i+k]:
        t[i+k]='D'
    ans+=get_score[(dic[t[i]]+2)%3]

print(ans)

Submission status: Accepted

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

ta = []
for i in range(n) :
  ta.append([t[i],1])

for i in range(n-k) :
  if ta[i][0] == ta[i+k][0] and ta[i][1] == ta[i+k][1]: 
    ta[i+k][1] = 0

ans = 0
for i in range(n) :
  if ta[i][1] == 1 :
    if ta[i][0] == 'r' :
      ans += p
    if ta[i][0] == 's' :
      ans += r
    if ta[i][0] == 'p' :
      ans += s

print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,k = inpm()
    r,s,p = inpm()
    t = list(input())
    past = [0 for _ in range(k)]
    ans = 0
    for i in range(n):
        if t[i] == 'r' and past[i%k] != 1:
            ans += p
            past[i%k] = 1
        elif t[i] == 's' and past[i%k] != 2:
            ans += r
            past[i%k] = 2
        elif t[i] == 'p' and past[i%k] != 3:
            ans += s
            past[i%k] = 3
        else:
            past[i%k] = 0
    print(ans)        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
score = [int(x) for x in input().split()]
translate = {'r':0, 's': 1, 'p': 2}
seq = [translate[x] for x in input()]
dp = [[float('-inf') for _ in range(3)] for _ in range(n+1)]
dp[0][0] = 0
dp[0][1] = 0
dp[0][2] = 0
for i in range(n):
    for j in range(3):
        if i < k:
            dp[i+1][j] =(score[j] if ((j+1) % 3) == seq[i] else 0)
        else:
            dp[i+1][j] = max(dp[i-k+1][(j+1) % 3], dp[i-k+1][(j+2) % 3]) + (score[j] if ((j+1) % 3) == seq[i] else 0) 
print(sum(max(dp[-1-i]) for i in range(k)))

Submission status: Accepted

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

for i in range(k):
    ans += dic[t[i]]

for i in range(k,n):
    if t[i] != t[i-k]:
        ans += dic[t[i]]
    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 = list(input())
d = {'r':P,'s':R,'p':S}
ans = 0
for i,c in enumerate(T):
    if i < K or c != T[i-K]:
        ans += d[c]
        continue
    else:
        T[i] = '_'
print(ans)

Submission status: Accepted

Solution code:
#149_D
from itertools import groupby
n, k = map(int, input().split())
r, s, p = map(int, input().split())
point = {'s':r, 'p':s, 'r':p}
t = input()
ans = 0
for i in range(k):
    t_ = t[i::k]
    cnt = groupby(list(t_))
    for te, c in cnt:
        ans += point[te] * -(-len(list(c)) // 2)
print(ans)

Submission status: Accepted

Solution code:
game_num, k = map(int, input().split())
r_score, s_score, p_score = map(int, input().split())
game = input()
score = 0
waste_r, waste_s, waste_p = [], [], []
count_waste_r = count_waste_s = count_waste_p = 0

for i in range(game_num):
    if i < k:
        pass
    elif game[i] == 'r' and game[i - k] == 'r' and not (i - k) in waste_r:
        count_waste_r += 1
        if len(waste_r) > k:
            waste_r.pop(0)
        waste_r.append(i)
    elif game[i] == 's' and game[i - k] == 's' and not (i - k) in waste_s:
        count_waste_s += 1
        if len(waste_s) > k:
            waste_s.pop(0)
        waste_s.append(i)
    elif game[i] == 'p' and game[i - k] == 'p' and not (i - k) in waste_p:
        count_waste_p += 1
        if len(waste_p) >  k:
            waste_p.pop(0)
        waste_p.append(i)

r_count, s_count, p_count = map(lambda x: game.count(x), ['r', 's', 'p'])

score += r_count * p_score + s_count * r_score + p_count * s_score
score -= count_waste_r * p_score + count_waste_s * r_score + count_waste_p * s_score
print(score)

Submission status: Accepted

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

s = {"r": P, "s": R, "p": S}
res = 0
for i in range(N):
    if i >= K:
        if T[i] == T[i-K]:
            T[i] = 0
            continue
    res += s[T[i]]

print(res)

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
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 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 = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
R, S, P = MAP()
T = input()
point = {"r": R, "s": S, "p": P}
win = {"r": "p", "s": "r", "p":"s"}

# Tに対して勝つ
win_T = [win[x] for x in T]

ans = 0
for i in range(N):
    if i < K:
        ans += point[win_T[i]]
    # 同じにしたら勝けどできないから変える
    elif win_T[i-K] == win_T[i]:
        win_T[i] = None
    else:
        ans += point[win_T[i]]
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(N):
    if i-K < 0 or T[i-K] != T[i]:
        if T[i] == "r":
            ans += P
        elif T[i] == "s":
            ans += R
        elif T[i] == "p":
            ans += S
    else:
        T[i] = "a"
print (ans)

Submission status: Accepted

Solution code:
import math

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


def Score(hand):
    if hand == "r":
        score = P
    elif hand == "s":
        score = R
    else:
        score = S
    return score


t = [[] for _ in range(K)]

for i in range(N):
    chk = i % K
    t[chk].append(T[i])

Ans = 0
for i in range(K):
    check = t[i]
    cnt = 1
    for j in range(len(check) - 1):
        if check[j] == check[j + 1]:
            cnt += 1
        else:
            Ans += Score(check[j]) * (math.ceil(cnt / 2))
            cnt = 1
    Ans += Score(check[-1]) * (math.ceil(cnt / 2))

print(Ans)

Submission status: Accepted

Solution code:
N,K = input().split(' ')
N = int(N)
K = int(K)
points = [int(x) for x in input().split(' ')]
line = input()
point = 0
W = {
  "r":"p",
  "s":"r",
  "p":"s"
}
P = {
  "r":points[0],
  "s":points[1],
  "p":points[2]
}
mem = [0]*K
for i in range(N):
  if i < K:
    mem[i] = W[line[i]]
    point += P[W[line[i]]]
  else:
    if mem[i%K] == W[line[i]]:
      mem[i%K] = 'N'
    else:
      mem[i%K] = W[line[i]]
      point += P[W[line[i]]]
print(point)

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):
    ans += P if T[i] == "r" else R if T[i] == "s" else S
    prev = T[i]
    for t in T[i::K][1:]:
        if t != prev:
            ans += P if t == "r" else R if t == "s" else S
            prev = t
        else:
            prev = "*"
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy

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

ans = 0
for i in range(k):
  n_ = (n - i) // k + (1 if (n-i) % k > 0 else 0)
  rsp = [0] * 3
  for j in range(n_):
    bef = deepcopy(rsp)
    if l[j * k + i] == "r":
      rsp[2] = max(bef[0], bef[1]) + p
      rsp[1] = max(bef[0], bef[2])
      rsp[0] = max(bef[1], bef[2])
    elif l[j * k + i] == "s":
      rsp[2] = max(bef[0], bef[1])
      rsp[1] = max(bef[0], bef[2])
      rsp[0] = max(bef[1], bef[2]) + r
    elif l[j * k + i] == "p":
      rsp[2] = max(bef[0], bef[1])
      rsp[1] = max(bef[0], bef[2]) + s
      rsp[0] = max(bef[1], bef[2])
  ans += max(rsp)
      
print(ans)

Submission status: Accepted

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

score=0

for i in range(N):
    if i-K<0 or T[i-K]!=T[i]:
        if T[i]=="r":
            score+=P
        elif T[i]=="p":
            score+=S
        elif T[i]=="s":
            score+=R
    else:
        T[i]="a"

print(score)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
z = 0
kachi = dict({"r": "p", "s": "r", "p": "s"})
tt = []
for i in range(n):
    tt.append(kachi[t[i]])
#print(t)
#print(tt)
for i in range(n - k):
    if tt[i] == tt[i + k]:
        tt[i+k] = "z"
kachi = dict({"r": r, "s": s, "p": p, "z": 0})
res = 0
for i in range(n):
    res += kachi[tt[i]]
print(res)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
T=input()
cnt=0
N=[0]*n
for i in range(n):
    if N[i]==1:
        continue
    if i+k<=n-1:
        if T[i]==T[i+k]:
            N[i+k]=1
    
    if T[i]=='r':
        cnt+=p
    elif T[i]=='s':
        cnt+=r
    else:
        cnt+=s

print(cnt)

Submission status: Accepted

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

def jk(n):
    if n == "r":
        return "p"
    elif n == "s":
        return "r"
    else:
        return "s"

def sc(n):
    if n == "r":
        return R
    elif n == "s":
        return S
    else:
        return P

ans = 0

hand = [[] for _ in range(K)]
for i in range(N):
    hand[i%K].append(T[i])

fight = [[] for _ in range(K)]
for i in range(K):
    for j in range(len(hand[i])):
        if j == 0:
            fight[i].append(jk(hand[i][j]))
            ans += sc(jk(hand[i][j]))
        elif hand[i][j] == hand[i][j-1]:
            if fight[i][j-1] == jk(hand[i][j]):
                fight[i].append(0)
            else:
                fight[i].append(jk(hand[i][j]))
                ans += sc(jk(hand[i][j]))
        else:
            fight[i].append(jk(hand[i][j]))
            ans += sc(jk(hand[i][j]))

print(ans)