Problem:


Score : 400 points

Problem Statement

At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)

Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):

R points for winning with Rock;

S points for winning with Scissors;

P points for winning with Paper.

However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string T. If the i-th character of T (1 \leq i \leq N) is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

if both players play the same hand, it is a draw.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

1 \leq R,S,P \leq 10^4

N,K,R,S, and P are all integers.

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.
We cannot earn more points, so the answer is 27.

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996



Sample input:
5 2
8 7 6
rsrpr


Sample output:
27

Submission status: Wrong Answer

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

for c in t:
    if c == 'r':
        point += p
    elif c == 's':
        point += r
    else:
        point += s


for i in range(k):
    slc = t[i::k]
    for j in range(len(slc)-1):
        if slc[j] == slc[j+1]:
            if slc[j+1] == 'r':
                point -= p
                if j != len((slc)) - 2:
                    if slc[j+2] == 'r':
                        slc = slc[:j+1] + ('p' if max(s, r) == s else 's') + slc[j+2:]
                    else:
                        slc = slc[:j+1] + ('p' if slc[j+2] == 's' else 'p') + slc[j+2:]
                else:
                    slc = slc[:j+1] + ('p' if max(s, r) == s else 's') + slc[j+2:]
            elif slc[j+1] == 's':
                point -= r
                if j != len((slc)) - 2:
                    if slc[j+2] == 's':
                        slc = slc[:j+1] + ('r' if max(p, s) == p else 'p') + slc[j+2:]
                    else:
                        slc = slc[:j+1] + ('r' if slc[j+2] == 'p' else 'r') + slc[j+2:]
                else:
                    slc = slc[:j+1] + ('r' if max(p, s) == p else 'p') + slc[j+2:]
            else:
                point -= s
                if j != len((slc)) - 2:
                    if slc[j+2] == 'p':
                        slc = slc[:j+1] + ('s' if max(r, p) == r else 'r') + slc[j+2:]
                    else:
                        slc = slc[:j+1] + ('s' if slc[j+2] == 'r' else 's' ) + slc[j+2:]
                else:
                    slc = slc[:j+1] + ('s' if max(r, p) == r else 'r') + slc[j+2:]

print(point)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
T_new = [] * N #勝つ手
T_new_num = [] * N #勝つ手の数値変換
T_new_num_2 = [] *N #各回で得られる得点

# 0 : r
# 1 : s
# 2 : p

for i in range(N) :
    if T[i] == 'r' :
        T_new.append('p')
    elif T[i] == 's' :
        T_new.append('r')
    else :
        T_new.append('s')
for i in range(N) : #数値に変換
    if T_new[i] == 'r' :
        T_new_num.append(0)
    elif T_new[i] == 's' :
        T_new_num.append(1)
    else :
        T_new_num.append(2)
#取りうる得点の配列
for i in range(N) :
    if T_new_num[i] == 0 :
        T_new_num_2.append(R)
    elif T_new_num[i] == 1 :
        T_new_num_2.append(S)
    else :
        T_new_num_2.append(P)
for i in range(K,N) :
    if (T_new_num_2[i-K] == T_new_num_2[i]) and (T_new_num_2[i-K] != 0) :
        T_new_num_2[i] = 0
print(sum(T_new_num_2))

Submission status: Wrong Answer

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


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

for i in range(k,n-1):
    if hands[i] == hands[i-k]:
        c = 'rsp'
        c = c.replace(hands[i],'')
        if i+k < n:
            c.replace(hands[i+k],'')
        
        if len(c) == 0:
            hands = hands[:i] + c + hands[i+1:]
        else:
            hands = hands[:i] + c[0] + hands[i+1:]

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

Submission status: Wrong Answer

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

takahashi = ''
tokuten = 0

for i in range(n):
    if i <= k:
        if t[i] == 'r':
            takahashi += 'p'
            tokuten += p
        elif t[i] == 'p':
            takahashi += 's'
            tokuten += s
        else:
            takahashi += 'r'
            tokuten += r
    else:
        if t[i] == 'r':
            if takahashi[i-2] == 'p':
                takahashi += 'r'
                tokuten += 0
            else:
                takahashi += 'p'
                tokuten += p
        elif t[i] == 'p':
            if takahashi[i-2] == 's':
                takahashi += 'p'
                tokuten += 0
            else:
                takahashi += 's'
                tokuten += s
        else:
            if takahashi[i-2] == 'r':
                takahashi += 's'
                tokuten += 0
            else:
                takahashi += 'r'
                tokuten += r

print(tokuten)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
g,c,p = map(int,input().split())
t = str(input())
l = ""
ans = 0
for i in range(len(t)):
    #print(l)
    if t[i] == "r": #ぐー
        wanthand = "p" #パー
    elif t[i] == "s": #チョキ
        wanthand = "r" #ぐー
    else:#ぱー
        wanthand = "s" #チョキ
    if i < k:
        if wanthand == "p":
            ans += p
        elif wanthand == "r":
            ans += g
        else:
            ans += c
        l += wanthand
    else:
        if wanthand != l[i-k]:
            if wanthand == "p":
                ans += p
            elif wanthand == "r":
                ans += g
            else:
                ans += c
            l += wanthand
        else:
            l += t[i]
            
print(ans)
#print(l)

Submission status: Wrong Answer

Solution code:
N_K = input().split()
N = int(N_K[0])
K = int(N_K[1])

R_S_P = input().split()
R = int(R_S_P[0])
S = int(R_S_P[1])
P = int(R_S_P[2])

T = input()

win_strategy = {
    "r": "p",
    "s": "r",
    "p": "s"
}

decision = ""
for index, value in enumerate(T):
    if (index <= K-1):
        decision += win_strategy[value]
    else:
        if (win_strategy[value] == decision[index-K]):
            decision += value
        else:
            decision += win_strategy[value]

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

points = 0
for i in range(N):
    if (decision[i] != T[i]):
        points += point_acquire[decision[i]]

print(points)

Submission status: Wrong Answer

Solution code:
gamenum, limit = [int(x) for x in input().split()]
ten_rock, ten_scissors, ten_paper = [int(x) for x in input().split()]
strategy_list = list(input())

tokuten_dict = {"r": ten_paper, "s":ten_rock, "p": ten_scissors}
strategy_dict = {"r": "p", "s": "r", "p": "s"}

tokuten = 0
history = []
i=1
check_idx = 0
for strategy in strategy_list:
    if(i - limit -1<0)or i ==1:
        tokuten = tokuten+tokuten_dict[strategy]
        history.append(strategy_dict[strategy])
    else:
        check_idx = i - limit -1
        if history[check_idx] == strategy_dict[strategy]:
            history.append(strategy)
        else:
            tokuten = tokuten+tokuten_dict[strategy]
            history.append(strategy_dict[strategy])
    i=i+1
print(tokuten)

Submission status: Wrong Answer

Solution code:
# 1行目の入力を空白で分割された数値として扱う
N, K = map(int, input().split())
# 2行目の入力を空白で分割された数値として扱う
R, S, P = map(int, input().split())
# 3行目の入力を文字列として扱う
T = str(input())

# 答えの準備
res = 0

# 自分の手
U = []


#
for i in range(0, N):
    if T[i] == 'r':
        if (K <= i) and (U[i - K] == 'P'):
            U.append('R')
        else:
            U.append('P')
            res += P
    if T[i] == 's':
        if (K <= i) and (U[i - K] == 'R'):
            U.append('S')
        else:
            U.append('R')
            res += R
    if T[i] == 'p':
        if (K <= i) and (U[i - K] == 'S'):
            U.append('P')
        else:
            U.append('S')
            res += S

#
print(res)

Submission status: Wrong Answer

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

result = 0
str_list = list(t)
j_list = []
for i in range(n):
    if i >= k:
        dame = str_list[i-k]
    else:
        dame = ""
    if str_list[i] == "r":
        if dame != "p":
            result += p
            str_list[i] = "p"
        else:
            str_list[i] = "r"
    elif str_list[i] == "s":
        if dame != "r":
            result += r
            str_list[i] = "r"
        else:
            str_list[i] = "s"
    elif str_list[i] == "p":
        if dame != "s":
            result += s
            str_list[i] = "s"
        else:
            str_list[i] = "p"
print(result)

Submission status: Wrong Answer

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

batch = [T[i::K] for i in range(K)]

ans = 0
for b in batch:
    tmp = 0
    for p in 'rsp':
        t = 0
        before = p
        if p == win[b[0]]: t += points[win[b[0]]]
        for i in range(1,len(b)):
            if win[b[i]] != before:
                t += points[win[b[i]]]
                before = win[b[i]]
            else: before = b[i]
        if t > tmp: tmp = t
    ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
gamenum, limit = [int(x) for x in input().split()]
ten_rock, ten_scissors, ten_paper = [int(x) for x in input().split()]
strategy_list = list(input())

tokuten_dict = {"r": ten_paper, "s":ten_rock, "p": ten_scissors}
strategy_dict = {"r": "p", "s": "r", "p": "s"}

tokuten = 0
history = []
i=1
check_idx = 0
for strategy in strategy_list:
    if(limit>i)or i ==1:
        tokuten = tokuten+tokuten_dict[strategy]
        history.append(strategy_dict[strategy])
    else:
        check_idx = i - limit -1
        if history[check_idx] == strategy_dict[strategy]:
            history.append(strategy)
        else:
            tokuten = tokuten+tokuten_dict[strategy]
            history.append(strategy_dict[strategy])
    i=i+1
print(tokuten)

Submission status: Wrong Answer

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

count = 0
result = []

command = ["r", "s", "p"]

def next(x):
  if x == "r":
    return "p"
  elif x == "s":
    return "r"
  elif x == "p":
    return "s"

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

count = 0

def solve(index):
  global count
  n = next(T[index])
  winnable = index < K or (len(result) >= K and result[-K] != n)
  if winnable:
    count += get_point(n)
    return n
  else:
    if N - 1 >= index + 2:
      m = next(T[index+2])
      return list(filter(lambda x: x != n and x != m, command))[0]
    else:
      # 得点に関係しないので適当なもの返す
      return list(filter(lambda x: x != n, command))[0]

for i in range(N):
  x = T[i]
  result.append(solve(i))

print(count)

Submission status: Wrong Answer

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

if k>n:
  print(sum(l))
else:
  for j in range(k,n):
    if l[j] == l[j-k]:
      l[j] = 0
  print(sum(l))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r,s,p = map(int, input().split())
kind = {}
kind["r"] = p
kind["s"] = r
kind["p"] = s
t = input()
acc = [0 for i in range(n + k + 1)]
for i in range(n):
    acc[i] =  acc[i-1] + kind[t[i]]
dp = [[0 for i in range(3)] for j in range(n + k)]
for i in range(n):
    if t[i] == "r":
        dp[i+k][0] = max(dp[i][1], dp[i][2]) + acc[i-1] - acc[i-k]
        dp[i+k][1] = max(dp[i][0], dp[i][2]) + acc[i-1] - acc[i-k]
        dp[i+k][2] = max(dp[i][0], dp[i][1]) + acc[i] - acc[i-k]
    elif t[i] == "s":
        dp[i+k][0] = max(dp[i][1], dp[i][2]) + acc[i] - acc[i-k]
        dp[i+k][1] = max(dp[i][0], dp[i][2]) + acc[i-1] - acc[i-k]
        dp[i+k][2] = max(dp[i][0], dp[i][1]) + acc[i-1] - acc[i-k]
    else:
        dp[i+k][0] = max(dp[i][1], dp[i][2]) + acc[i-1] - acc[i-k]
        dp[i+k][1] = max(dp[i][0], dp[i][2]) + acc[i] - acc[i-k]
        dp[i+k][2] = max(dp[i][0], dp[i][1]) + acc[i-1] - acc[i-k]
print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split(' '))
r,s,p = map(int, input().split(' '))
di = {'r': p,'s':r,'p':s}
t = input()
li = [list(map(lambda x: di[x],list(t[i::k]))) for i in range(k)]
x = 0
for y,i in enumerate(li):
    for j in range(len(i)-1):
        w1 = i[j]
        w2 = i[j+1]
        if w1 == w2:
            li[y][j+1] = 0
    x += sum(li[y])
print(x)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    R, S, P = (int(i) for i in input().split())
    T = input()
    dp = [[0 for _ in range(N+1)] for _ in range(3)]
    pre = []
    for i, t in enumerate(T):
        check = False
        if i < K:
            if t == "r":
                dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
                dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
                dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + P
            elif t == "s":
                dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + R
                dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
                dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
            elif t == "p":
                dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
                dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + S
                dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
        else:
            if t == "r":
                dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
                dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
                dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + P
            elif t == "s":
                dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + R
                dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
                dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
            elif t == "p":
                dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
                dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + S
                dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
            if dp[pre[-K]][i+1] == max(dp[0][i+1], dp[1][i+1], dp[2][i+1])\
                    and i + K < N:
                if pre[-K] != 1 and T[i+K] == "r":
                    dp[2][i+1] = 0  # パー,2
                    dp[0][i+1] = 0
                    pre.append(1)  # パー,2を温存したい
                    check = True
                elif pre[-K] != 2 and T[i+K] == "s":
                    dp[0][i+1] = 0
                    dp[1][i+1] = 0
                    pre.append(2)
                    check = True
                elif pre[-K] != 0 and T[i+K] == "p":
                    dp[1][i+1] = 0
                    dp[2][i+1] = 0
                    pre.append(0)
                    check = True
                else:
                    dp[pre[-K]][i+1] = 0
            else:
                dp[pre[-K]][i+1] = 0

        if not(check):
            if dp[0][i+1] == max(dp[0][i+1], dp[1][i+1], dp[2][i+1]):
                dp[1][i+1] = 0
                dp[2][i+1] = 0
                pre.append(0)
            elif dp[1][i+1] == max(dp[0][i+1], dp[1][i+1], dp[2][i+1]):
                dp[2][i+1] = 0  # パー,2
                dp[0][i+1] = 0
                pre.append(1)
            else:
                dp[0][i+1] = 0
                dp[1][i+1] = 0
                pre.append(2)
    print(max(dp[0][N], dp[1][N], dp[2][N]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy

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

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

choices = []
choices.append(['r'])
choices.append(['s'])
choices.append(['p'])

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

    lst = [DP[0][i-1],DP[1][i-1],DP[2][i-1]]
    m = max(lst)
    idx = lst.index(m)

    if i < K:
        DP[0][i] = m+r
        DP[1][i] = m+s
        DP[2][i] = m+p
    else:
        DP[0][i] = m+r if choices[idx][i-K] != 'r' else 0
        DP[1][i] = m+s if choices[idx][i-K] != 's' else 0
        DP[2][i] = m+p if choices[idx][i-K] != 'p' else 0
    
    tmp1 = copy.deepcopy(choices[idx])
    tmp1.append('r')
    tmp2 = copy.deepcopy(choices[idx])
    tmp2.append('s')
    tmp3 = copy.deepcopy(choices[idx])
    tmp3.append('p')

    choices[0] = tmp1
    choices[1] = tmp2
    choices[2] = tmp3
    
print(max(DP[0][N-1],DP[1][N-1],DP[2][N-1]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
a = list()
for i in range(k):
    for j in range(int((n - i - 1) / k) + 1):
        if t[j * k + i] == "r":
            b = p
        elif t[j * k + i] == "s":
            b = r
        else:
            b = s
        a.append(b)
    a.append("/")
    
c = 2
ans = 0
e = 0
for i in range(len(a) - 1):
    if a[i] == a[i + 1]:
        c += 1
        d = a[i]
        e = 1
    elif a[i] != a[i + 1] and e == 1:
        ans += int(c / 2) * d
        c = 2
        d = 0
        e = 0
    elif a[i] != a[i + 1] and a[i] != "/":
        ans += a[i]
        
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T=list(input())
kachi = {'r':'p', 's':'r', 'p':'s'}
aico = {'r':'r', 's':'s', 'p':'p'}
make = {'r':'s', 's':'p', 'p':'r'}
point = {'r':R, 's':S, 'p':P}
count = 0
me=['' for j in range(N)]

for i in range(N):
  if i<K:
    count = count + point[kachi[T[i]]]
    me[i] = kachi[T[i]]
  else:
    if me[i-K] == kachi[T[i]]:
      if i+K<N:
        if T[i+K] == aico[T[i]]:
          me[i] = make[T[i]]
        else:
          me[i] = aico[T[i]]
      else:
        me[i] = aico[T[i]]
    else:
      count = count + point[kachi[T[i]]]
      me[i] = kachi[T[i]]
print(count)

Submission status: Wrong Answer

Solution code:
n = input()    
m = n.split()
p = [int(i) for i in m]
n = input()    
m = n.split()
P = [int(i) for i in m]
n = input()
list = [""]*p[1]
for i, value in enumerate(n):
    list[i%p[1]] =list[i%p[1]] + value
able = [True,True,True]
A = 0
for i in list:
    able = [True,True,True]
    for j in i:
        if j == "r":
            if able[2]:
                A = A + P[2]
                able[2] = False
            else:
                able = [True,True,True]
        if j == "s":
            if able[0]:
                A = A + P[0]
                able[0] = False
            else:
                able = [True,True,True]
        if j == "p":
            if able[1]:
                A = A + P[1]
                able[1] = False
            else:
                able = [True,True,True]

print(A)

Submission status: Wrong Answer

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

winners = [R, S, P]
min_win = min(winners)
min_win_index = winners.index(min_win)

if min_win_index == 0:
    min_winner = 'r'
elif min_win_index == 1:
    min_winner = 's'
else:
    min_winner = 'p'

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

score = {'p': P, 'r': R, 's': S}
hand = {'r': 'p', 's': 'r', 'p': 's'}
H = [' '] * N

ans = 0
for i, c in enumerate(T):
    if i - K >= 0 and hand[c] == H[i - K]:
        H[i] = c
        s = 0
    else:
        H[i] = hand[c]
        s = score[hand[c]]

    ans += s

ans1 = 0
for i in range(N):
    c = T[N - 1 - i]
    if i - K >= 0 and hand[c] == H[i - K]:
        H[i] = c
        s = 0
    else:
        H[i] = hand[c]
        s = score[hand[c]]

    ans1 += s

print(max(ans, ans1))

Submission status: Wrong Answer

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

r_point = t.count('s') * r
s_point = t.count('p') * s
p_point = t.count('r') * p

sum_point = r_point+s_point+p_point

for i, moji in enumerate(t):
    if i+k >= len(t):
        break
    print(t[i], t[i+k])
    if t[i] == 'r' and t[i+k] == 'r':
        sum_point -= p
        t[i+k] = 'x'
    if t[i] == 's' and t[i+k] == 's':
        sum_point -= r
        t[i+k] = 'x'
    if t[i] == 'p' and t[i+k] == 'p':
        sum_point -= s
        t[i+k] = 'x'

print(sum_point)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
d = {'r': 'p', 's': 'r', 'p': 's'}
a = {'r' : R, 's' : S, 'p' : P}
l = [d[s] for s in T]
lf = l[:]
cnt = 0
fcnt = 0
for i, s in enumerate(T):
    if i < K:
        cnt += a[l[i]]
        lf[i] = s
        continue
    if s == 'r' and l[i-K] != 'p':
        cnt += P
    elif s == 'r' and l[i-K] == 'p':
        #cnt += R
        l[i] = 'r'

    if s == 's' and l[i-K] != 'r':
        cnt += R
    elif s == 's' and l[i-K] == 'r':
        #cnt += S
        l[i] = 's'

    if s == 'p' and l[i-K] != 's':
        cnt += S
    elif s == 'p' and l[i-K] == 's':
        #cnt += P
        l[i] = 'p'
    

     
    if s == 'r' and lf[i-K] != 'p':
        fcnt += P
    elif s == 'r' and lf[i-K] == 'p':
        #cnt += R
        lf[i] = 'r'

    if s == 's' and lf[i-K] != 'r':
        fcnt += R
    elif s == 's' and lf[i-K] == 'r':
        #cnt += S
        lf[i] = 's'

    if s == 'p' and lf[i-K] != 's':
        fcnt += S
    elif s == 'p' and lf[i-K] == 's':
        #cnt += P
        lf[i] = 'p'

print(max(cnt, fcnt))

Submission status: Wrong Answer

Solution code:
def ten(arr,R,S,P):
  ans = 0
  num = 0
  length = len(arr)
  print(length)
  for i in range(length):
    if i == 0:
      if arr[i] == "r":
        ans = ans + P
        num = i
      elif arr[i] == "s":
        ans = ans + R
        num = i
      else:
        ans = ans + S
        num = i

    elif i > 0 and arr[i] != arr[i-1]:
      if arr[i] == "r":
        ans = ans + P
        num = i
      elif arr[i] == "s":
        ans = ans + R
        num = i
      else:
        ans = ans + S
        num = i
        
    elif i > 0 and arr[i] == arr[i-1] and int(num+1) != i:
      if arr[i] == "r":
        ans = ans + P
        num = i
      elif arr[i] == "s":
        ans = ans + R
        num = i
      else:
        ans = ans + S
        num = i
    
  return ans

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

T = list(T)
arr = []

for i in range(K):
  a = T[i::K]
  arr.append(a)

ans = 0

for i in arr:
  ans = ans + ten(i,R,S,P)

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = [int(_) for _ in input().split()]
r_s, s_s, p_s = [int(_) for _ in input().split()]
t = input()

s = ''
for i in range(k):
    s += t[i]

c = 0
for start in range(k):
    for i in range(start + k, n, k):
        if t[i] == t[i - k]:
            c += 1
            if c % 2 == 0:
                s += t[i]
        else:
            s += t[i]
            c = 0

ans = 0
for i in range(len(s)):
    if s[i] == 'r':
        ans += p_s
    elif s[i] == 's':
        ans += r_s
    else:
        ans += s_s
print(ans)

Submission status: Wrong Answer

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

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

print(np.sum(T))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())
V=[]
x=0
for i in T:
  if i=="r":
    V.append("p")
  elif i=="s":
    V.append("r")
  else:
    V.append("s")
#print(V)
for i in range(len(V)):
  if i>=K and V[i]==V[i-K]:
    #print(V[i],V[i-K])
    x=x+0
    if V[i]=="r":
      V[i]="s"
    elif V[i]=="s":
      V[i]="p"
    else:
      V[i]="r"
    continue
  elif V[i]=="r":
    x=x+R
  elif V[i]=="s":
    x=x+S
  elif V[i]=="p":
    x=x+P

print(x)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split(' '))
r, s, p = map(int, input().split(' '))
t = input()
prls = [0] * k
point = 0
for i in range(n):
    if i < k:
        if t[i] == "r":
            prls[i] = "p"
            point += p
        elif t[i] == "s":
            prls[i] = "r"
            point += r
        elif t[i] == "p":
            prls[i] = "s"
            point += s
    else:
        if t[i] == "r":
            if prls[i % k] == "p":
                prls[i % k] = "r"
            else:
                prls[i % k] = "p"
                point += p
        elif t[i] == "s":
            if prls[i % k] == "r":
                prls[i % k] = "s"
            else:
                prls[i % k] = "r"
                point += r
        elif t[i] == "p":
            if prls[i % k] == "s":
                prls[i % k] = "p"
            else:
                prls[i % k] = "s"
                point += s
print(point)

Submission status: Wrong Answer

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

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

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

print(sum(point))

Submission status: Wrong Answer

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

ans = 0
count = 0
tt = ''
tmp = ''
for i in range(n):  
  if t[i] == 'r':
    if tmp == 'p' and i >= k:
      tt = 'r'
    else:
      tt = 'p'
      ans+=p
  elif t[i] == 's':
    if tmp == 'r' and i >= k:
      tt = 's'
    else:
      tt = 'r'
      ans+=r
  elif t[i] == 'p':
    if tmp == 's' and i >= k:
      tt = 'p'
    else:
      tt = 's'
      ans+=s
  if i % k == 0:
    tmp = tt
print(ans)

Submission status: Wrong Answer

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


batch = [T[i::K] for i in range(K)]

ans = 0
for b in batch:
    tmp = 0
    pat = [win[b[0]],b[0]]
    for p in pat:
        t = 0
        before = p
        if p == win[b[0]]: t += points[win[b[0]]]
        for i in range(1,len(b)):
            if win[b[i]] != before:
                t += points[win[b[i]]]
                before = win[b[i]]
            else: before = b[i]
        if t > tmp: tmp = t
    ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = str(input())
A = []
point = 0
for i in range(K):
  if T[i] == 'r':
    A.append('p')
    point += P
  elif T[i] == 's':
    A.append('r')
    point += R
  else:
    A.append('s')
    point += S

for i in range(K, N):
  if T[i] == 'r':
    if A[i-K] == 'p':
      A.append('r')
      continue
    A.append('p')
    point += P
  elif T[i] == 's':
    if A[i-K] == 'r':
      A.append('s')
      continue
    A.append('r')
    point += R
  else:
    if A[i-K] == 's':
      A.append('p')
      continue
    A.append('s')
    point += S
print(point)