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:
a, k = input().split()
a = int(a)
k = int(k)
r, s, p = input().split()
r = int(r)
s = int(s)
p = int(p)
t = input()

point = 0

for x in range(len(t)):
    pos_check = x - k
    if pos_check >= 0:
        if t[pos_check] == t[x]:
            continue
    if t[x] == "r":
        point += p
    elif t[x] == "s":
        point += r
    elif t[x] == "p":
        point += s

print(point)

Submission status: Wrong Answer

Solution code:
# D
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ans = 0
dct = {'r': R, 's': S, 'p': P}
win = {'r': 'p', 's': 'r', 'p': 's'}
aiko = {'r': 'r', 's': 's', 'p': 'p'}
lose = {'r': 's', 's': 'p', 'p': 'r'}

hands = []
for i, s in enumerate(T):
    if (i+1 <= K):
        hand = win[s]
        hands.append(hand)
        ans += dct[hand]
    else:
        hand = win[s]
        if (hands[i-K] != hand):
            ans += dct[hand]
            hands.append(hand)
        else:
            if (i < N-K):
                if (T[i+K] != aiko[s]):
                    hands.append(aiko[s])
                elif (T[i+K] != lose[s]):
                    hands.append(lose[s])
            else:
                hands.append(lose[s])
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())
    player = []
    win = [True for i in range(N)]
    for i in T:
        if i == 'r':
            player.append('p')
        elif i == 's':
            player.append('r')
        elif i == 'p':
            player.append('s')


    for k in range(1, K+1):
        for i in range(k-1, N, K):
            if i >= K and i < N - K:
                if player[i] in [player[i+K], player[i-K]]:
                    win[i] = False
                    if 'r' not in [player[i+K], player[i-K]]:
                        player[i] = 'r'
                    elif 's' not in [player[i+K], player[i-K]]:
                        player[i] = 's'
                    elif 'p' not in [player[i+K], player[i-K]]:
                        player[i] = 'p'
    
    rcnt = 0
    scnt = 0
    pcnt = 0
    for i in range(N):
        if win[i]:
            if player[i] == 'r':
                rcnt += 1
            if player[i] == 's':
                scnt += 1
            if player[i] == 'p':
                pcnt += 1
    
    ans = rcnt * R + scnt * S + pcnt * P
    print(ans)
                
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
HtoP = {"r":p,"s":r,"p":s}
t = list(input())
mscore = 0
for i in t:
    mscore += HtoP[i]


while len(t)%k != 0:
    t.append("z")
step = len(t)//k

for i in range(k):
    renzoku = 1
    for j in range(i,len(t)-k,k):
        
        d0 = t[j]
        d1 = t[j+k]
        if d1 == "z":
            break
        
        if d0 == d1:
            renzoku += 1
        elif renzoku >= 2:
            mscore -= (renzoku//2)*HtoP[d0]
            renzoku = 0
        else:
            renzoku = 0
    mscore  -= (renzoku//2)*HtoP[d0]
print(mscore)

Submission status: Wrong Answer

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

res = 0

def change(hand):
    if hand == 'r':
        return 'p'

    if hand == 's':
        return 'r'

    if hand == 'p':
        return 's'

memo = []
for (i,t) in enumerate(T):
    if i > K-1:
        if memo[i-K] == change(t):
          memo.append(t)
          continue
 
    if t == 'r':
        res = res+P
        memo.append(change(t))

    if t == 's':
        res = res+R
        memo.append(change(t))

    if t == 'p':
        res = res+S
        memo.append(change(t))

print(res)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
dic = {'r':r, 's':s,'p':p}
moves = input()
res = 0
res_str = [0]*n
for i in range(n):
	if moves[i] == 'r':
		if i>=k:
			if res_str[i-k] == 'p':
				res_str[i] = 'r'
			else:
				res_str[i] = 'p'
		else:
			res_str[i] = 'p'
	elif moves[i] == 'p':
		if i>=k:
			if res_str[i-k] == 's':
				res_str[i] = 'p'
			else:
				res_str[i] = 's'
		else:
			res_str[i] = 's'
	elif moves[i] == 's':
		if i>=k:
			if res_str[i-k] == 'r':
				res_str[i] = 's'
			else:
				res_str[i] = 'r'
		else:
			res_str[i] = 'r'
for i in range(n):
	if moves[i] != res_str[i]:
		res += dic[res_str[i]]
print(res)

Submission status: Wrong Answer

Solution code:
#D - Prediction and Restriction
N,K = map(int, input().split())
R,S,P = map(int, input().split())
t = min(R,S,P)
if t == R:
    t_1 = "r"
elif t == S:
    t_1 = "s"
else:
    t_1 = "p"
ans = 0
T = str(input())
C = []
DP = []
for i in range(N):

    if T[i] == "p":
        C.append("s")
        DP.append(S)
    elif T[i] == "s":
        C.append("r")
        DP.append(R)
    else:
        C.append("p")
        DP.append(P)

for k in range(K):
    ans += DP[k]

for j in range(K,N):
    if DP[j] == DP[j-K]:
        ans += 0
        DP[j] = 0
    else:
        ans += DP[j]

print(ans)

Submission status: Wrong Answer

Solution code:
in_li = list(map(int,input().split()))
N = in_li[0]
K = in_li[1]
in_li2 = list(map(int,input().split()))
R = in_li2[0]
S = in_li2[1]
P = in_li2[2]
T = input()

res_l = []
for i in range(K) :
    if T[i] == 'r' :
        res_l.append(P)
    elif T[i] == 'p' :
        res_l.append(S)
    else :
        res_l.append(R)
for i in range(K,N) :
    if T[i] == 'r' :
        if P not in res_l[i-K:i+1] :
            res_l.append(P)
        else :
            res_l.append(0)
    elif T[i] == 'p' :
        if S not in res_l[i-K:i+1] :
            res_l.append(S)
        else :
            res_l.append(0)
    elif T[i] == 's' :
        if R not in res_l[i-K:i+1] :
            res_l.append(R)
        else :
            res_l.append(0)


print(sum(res_l))

Submission status: Wrong Answer

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

tli = []
while T > 0:
    tli.append(T%10)
    T //= 10
tli.reverse()

a =len(tli)
li = []
for i in range(K):
    b = a//K+1
    li.append(tli[i::K])

mli = []
sw = 0
for j in range(len(li)):
    for k in range(len(li[j])-1):
        if li[j][k] == li[j][k+1] and sw == 0:
            mli.append(li[j][k+1])
            sw = 1
        else:
            sw = 0

score = sum(tli)-sum(mli)
print(score)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
hands = {"r": "p", "s": "r", "p": "s"}
points = {"r": r, "s": s, "p": p}
my_hands = ""
score = 0

for i in range(n):
    if (i >= k):
        if (hands[t[i]] != my_hands[i-k]):
            my_hand = hands[t[i]]
            score = score + points[my_hand]
            my_hands = my_hands + my_hand
        else:
            my_hand = t[i]
            my_hands = my_hands + my_hand
    else:
        my_hand = hands[t[i]]
        score = score + points[my_hand]
        my_hands = my_hands + my_hand

print(score)

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
r,s,p =map(int,input().split())
t=input()
pm=0
for i in range(n):
    if t[i]=='r':pm+=r
    elif t[i]=='s':pm+=s
    else:pm+=p
cr=0
cs=0
cp=0
for i in range(n-k):
    if t[i] ==t[i+k]:
        if t[i]=='r':cr+=1
        elif t[i]=='s':cs+=1
        else:cp+=1
ccr=math.floor(cr/2)*r
ccs=math.floor(cs/2)*s
ccp=math.floor(cp/2)*p
pm =pm-(ccr+ccs+ccp)
        
print(pm)

Submission status: Wrong Answer

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

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

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

total = 0

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

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

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

Submission status: Wrong Answer

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

beforeK = T[:K]
afterK = T[K:]

ans = 0
r = re.findall('r', T)
s = re.findall('s', T)
p = re.findall('p', T)

ans = P*len(r) + R*len(s) + S*len(p)

countr = 0
counts = 0
countp = 0

for i in range(K, N-1, 1):
    if listT[i] == listT[i-K]:
        if listT[i] == 'r':
            countr += 1
        elif listT[i] == 's':
            counts += 1
        else:
            countp += 1

if countr == 1:
    ans -= P
elif countr == 0:
    ans = ans
else:
    ans -= P*(round(countr/2))

if counts == 1:
    ans -= R
else:
    ans -= R*(round(counts/2))

if countp == 1:
    ans -= S
else:
    ans -= S*(round(countp//2))

print(int(ans))

Submission status: Wrong Answer

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

count = 0
hantei = 0
for i in range(k):
    st2 = st[i::k]
    r_c = st[i::k].count("r")
    s_c = st[i::k].count("s")
    p_c = st[i::k].count("p")
    for j in range(len(st2)-2):
        tmp = st2[j]
        if j > 1:
            prev = st2[j+2]
        else:
            prev = 'x'

        if (st2[j+1]==tmp) & (tmp != prev):
            if st2[j+1]=='r':
                r_c -= 1
            elif st2[j+1]=='s':
                s_c -= 1
            else:
                p_c -= 1
    count += (r_c * p + s_c * r + p_c * s)
    
print(count)

Submission status: Wrong Answer

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

res = 0

def change(hand):
    if hand == 'r':
        return 'p'

    if hand == 's':
        return 'r'

    if hand == 'p':
        return 's'

memo = []
for (i,t) in enumerate(T):
    if i > K-1:
        if memo[i-K] == change(t):
          memo.append(t)
          continue
 
    if t == 'r':
        res = res+P
        memo.append(change(t))

    if t == 's':
        res = res+R
        memo.append(change(t))

    if t == 'p':
        res = res+S
        memo.append(change(t))


print(res)

Submission status: Wrong Answer

Solution code:
in_li = list(map(int,input().split()))
N = in_li[0]
K = in_li[1]
in_li2 = list(map(int,input().split()))
R = in_li2[0]
S = in_li2[1]
P = in_li2[2]
T = input()
res_l = []
for i in range(K) :
    if T[i] == 'r' :
        res_l.append(P)
    elif T[i] == 'p' :
        res_l.append(S)
    else :
        res_l.append(R)
for i in range(K,N) :
    if T[i] == 'r' :
        if P in res_l[i-K:i+1] :
            res_l.append(P)
        else :
            res_l.append(0)
    elif T[i] == 'p' :
        if S not in res_l[i-K:i+1] :
            res_l.append(S)
        else :
            res_l.append(0)
    elif T[i] == 's' :
        if R not in res_l[i-K:i+1] :
            res_l.append(R)
        else :
            res_l.append(0)
print(sum(res_l))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=str(input())
count=0
x=0
rsp=0
while(x<=n-1):
  if(t[x]=="r"):
    if(rsp==3):
      rsp=0
    else:
      count+=p
      rsp=3
  elif(t[x]=="s"):
    if(rsp==1):
      rsp=0
    else:
      count+=r
      rsp=1
  elif(t[x]=="p"):
    if(rsp==2):
      rsp=0
    else:
      count+=s
      rsp=2
  x+=1
print(count)

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().split()]
R,S,P = [int(i) for i in input().split()]
T = input()
wins = {'r':P, 'p':S, 's':R}
moves = {'r':'p','p':'s','s':'r'}
pastMoves = []
score =0
for i in range(len(T)):
    move = moves[T[i]]
    if(len(pastMoves)<1):
        score += wins[T[i]]
        pastMoves.append(move)
    else:
        if(i<K):
            score += wins[T[i]]
            pastMoves.append(move)
        else:
            if(not(move == pastMoves[i-K])):
                score += wins[T[i]]
                pastMoves.append(move)
            else:
                pastMoves.append(T[i])
print(score)

Submission status: Wrong Answer

Solution code:
in_li = list(map(int,input().split()))
N = in_li[0]
K = in_li[1]
in_li2 = list(map(int,input().split()))
R = in_li2[0]
S = in_li2[1]
P = in_li2[2]
T = input()
res_l = []
for i in range(K) :
    if T[i] == 'r' :
        res_l.append(P)
    elif T[i] == 'p' :
        res_l.append(S)
    else :
        res_l.append(R)
for i in range(K,N) :
    if T[i] == 'r' :
        if P in res_l[i-K:i+1] :
            res_l.append(0)
        else :
            res_l.append(P)
    elif T[i] == 'p' :
        if S in res_l[i-K:i+1] :
            res_l.append(0)
        else :
            res_l.append(S)
    elif T[i] == 's' :
        if R in res_l[i-K:i+1] :
            res_l.append(0)
        else :
            res_l.append(R)
print(sum(res_l))

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().split()]
R,S,P = [int(i) for i in input().split()]
T = input()
wins = {'r':P, 'p':S, 's':R}
moves = {'r':'p','p':'s','s':'r'}
pastMoves = []
score =0
for i in range(len(T)):
    move = moves[T[i]]
    if(len(pastMoves)<K):
        score += wins[T[i]]
        pastMoves.append(move)
    else:
        if(i<K):
            score += wins[T[i]]
            pastMoves.append(move)
        else:
            if(not(move == pastMoves[i-K])):
                score += wins[T[i]]
                pastMoves.append(move)
            else:
                pastMoves.append(T[i])
print(score)

Submission status: Wrong Answer

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

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

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

    results.append(result)
    hands.append(hand)

score=0
i=0
for hand in hands:
    if results[i]:
        if hand == "r":
            score+=r
        elif hand == "s":
            score+=s
        else:
            score+=p
    i+=1
print (score)

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 and 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:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
#point = {'r':P, 's':R, 'p':S}
#print(point)
T = input()

r_num = 0
s_num = 0
p_num = 0

mycurrent = ['a' for _ in range(K)]

for n in range(N):
    if T[n] == 'r':
        me = 'p'
    if T[n] == 's':
        me = 'r'
    if T[n] == 'p':
        me = 's'
    
    if mycurrent[n%K] != me:
        if me == 'r':
            r_num += 1
            mycurrent[n%K] = me
        if me == 's':
            s_num += 1
            mycurrent[n%K] = me
        if me == 'p':
            p_num += 1
            mycurrent[n%K] = me
            
    else:
        mycurrent[n%K] = T[n]
        
    #print(r_num, s_num, p_num)
print(r_num* R + s_num* S + p_num*P)

Submission status: Wrong Answer

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

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

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

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


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

print(max_ans)


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

# print(max_ans)

Submission status: Wrong Answer

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

beforeK = T[:K]
afterK = T[K:]

ans = 0
r = re.findall('r', T)
s = re.findall('s', T)
p = re.findall('p', T)

ans = P*len(r) + R*len(s) + S*len(p)

countr = 0
counts = 0
countp = 0

for i in range(K, N-1, 1):
    if listT[i] == listT[i-K]:
        if listT[i] == 'r':
            countr += 1
        elif listT[i] == 's':
            counts += 1
        else:
            countp += 1

if countr == 1:
    ans -= P
elif countr == 0:
    ans = ans
else:
    ans -= P*((countr//2)+1)

if counts == 1:
    ans -= R
else:
    ans -= R*((counts//2)+1)

if countp == 1:
    ans -= S
else:
    ans -= S*((countp//2)+1)

print(int(ans))

Submission status: Wrong Answer

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

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


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


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


answer = 0
a = max(r,s,p)
c = min(r,s,p)
b = r+s+p -a-c
tk = t
t = [0] * n
for i in range(n):
    t[i] = tk[i]

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
K_again = K
point = 0
T = T.upper()
for i in T[0:]:
    if K==0:
        K=K_again
        continue
    if i == "S":
        point+=R
        K-=1
        continue
    elif i == "P":
        point+=S
        K-=1
        continue
    elif i == "R":
        point+=P
        K-=1
        continue
print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
N, K = map(int, sys.stdin.readline().split())
R, S, P = map(int, sys.stdin.readline().split())
#グーR チョキS パーP
T = sys.stdin.readline().rstrip()
cnt=0

c = Counter(T)
print(c['r'])
print(R, S, P)

Submission status: Wrong Answer

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

a = 0
b = 0
c = 0

#グーチョキパーのダブり数を求める
for i in range(K,N):
  if T[i] == T[i - K]:
    if T[i] == "r":
      a += 1
    if T[i] == "s":
      b += 1
    if T[i] == "p":
      c += 1
      
#ダブるなら回数を調整し、手を出せない数を求める
if a > 0:
  a = (a + 1) // 2
if b > 0:
  b = (b + 1) // 2
if c > 0:
  c = (c + 1) // 2

#手の数
r = T.count("r")
s = T.count("s")
p = T.count("p")

#手の数から出せない手の数を引き、出せる手の数とスコアをかける
r = r - a
s = s - b
p = p - c

print((s * R) + (p * S) + (r * P))

Submission status: Wrong Answer

Solution code:
# D
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ans = 0
dct = {'r': R, 's': S, 'p': P}
win = {'r': 'p', 's': 'r', 'p': 's'}
aiko = {'r': 'r', 's': 's', 'p': 'p'}
lose = {'r': 's', 's': 'p', 'p': 'r'}

hands = []
for i, s in enumerate(T):
    if (i+1 <= K):
        hand = win[s]
        hands.append(hand)
        ans += dct[hand]
    else:
        hand = win[s]
        if (hands[i-K] != hand):
            ans += dct[hand]
            hands.append(hand)
        else:
            if (i < N-K):
                if (T[i+K] != aiko[s]):
                    hands.append(aiko[s])
                elif (T[i+K] != lose[s]):
                    hands.append(lose[s])
            else:
                hands.append(aiko[s])
print(ans)

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()
    pre = []
    ans = 0
    for i, t in enumerate(T):
        if t == "r":
            ans += P
            pre.append("p")
        elif t == "s":
            ans += R
            pre.append("r")
        elif t == "p":
            ans += S
            pre.append("s")

        if K <= i:
            if pre[-(K+1)] == "r" and pre[-1] == "r":
                ans -= R
                if i + K < N and T[i+K] == "r":
                    pre[-1] = "s"
                elif i + K < N and T[i+K] == "p":
                    pre[-1] = "p"
                elif i + K < N and T[i+K] == "s":
                    pre[-1] = "p"
                else:
                    pre[-1] = "p"
            elif pre[-(K+1)] == "s" and pre[-1] == "s":
                ans -= S
                if i + K < N and T[i+K] == "r":
                    pre[-1] = "r"
                elif i + K < N and T[i+K] == "p":
                    pre[-1] = "p"
                elif i + K < N and T[i+K] == "s":
                    pre[-1] = "p"
                else:
                    pre[-1] = "p"
            elif pre[-(K+1)] == "p" and pre[-1] == "p":
                ans -= P
                if i + K < N and T[i+K] == "r":
                    pre[-1] = "s"
                elif i + K < N and T[i+K] == "p":
                    pre[-1] = "r"
                elif i + K < N and T[i+K] == "s":
                    pre[-1] = "r"
                else:
                    pre[-1] = "r"

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(k):
  d=1
  for j in range(i,n,k):
    if j+k<n:
      if t[j]==t[j+k]:
        d+=1
        if j+k==(n-1):
          if t[j]=='p':
              count-=S*(d//2)
   
          if t[j]=='s':
              count-=R*(d//2)
          
          if t[j]=='r':
              count-=P*(d//2)
   
      else:
          if t[j]=='p':
            count-=S*(d//2)
       
          if t[j]=='s':
            count-=R*(d//2)
     
          if t[j]=='r':
            count-=P*(d//2)
        
          d=1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = np.tile(np.array(A),(N,1))

Submission status: Wrong Answer

Solution code:
in_li = list(map(int,input().split()))
N = in_li[0]
K = in_li[1]
in_li2 = list(map(int,input().split()))
R = in_li2[0]
S = in_li2[1]
P = in_li2[2]
T = input()
res_l = []
for i in range(K) :
    if T[i] == 'r' :
        res_l.append(P)
    elif T[i] == 'p' :
        res_l.append(S)
    else :
        res_l.append(R)
for i in range(K,N) :
    if T[i] == 'r' :
        if P not in res_l[i-K:i+1] :
            res_l.append(P)
        else :
            res_l.append(0)
    elif T[i] == 'p' :
        if S not in res_l[i-K:i+1] :
            res_l.append(S)
        else :
            res_l.append(0)
    elif T[i] == 's' :
        if R not in res_l[i-K:i+1] :
            res_l.append(R)
        else :
            res_l.append(0)
print(sum(res_l))

Submission status: Wrong Answer

Solution code:
from collections import deque

n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = deque(list(s for s in input()))

best_hand = {'r': 'p', 's': 'r', 'p': 's'}
ban = []
cand = ''

while t:
    cpu = t.popleft()
    
    if len(ban) < 2:
        add_hand = best_hand[cpu]
    else:
        ban_hand = ban.pop(0)
        if best_hand[cpu] == ban_hand:
            add_hand = 'e'
        else:
            add_hand = best_hand[cpu]
    ban.append(add_hand)
    cand += add_hand
    
print(p*cand.count('p') + s*cand.count('s') + r*cand.count('r'))

Submission status: Wrong Answer

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

a = [0] * N
ans = 0
for i in range(K):
    a[i] = h[T[i]]
    ans += t[a[i]]

for i in range(K, N):
    if h[T[i]] != a[i - K]:
        a[i] = h[T[i]]
        ans += t[a[i]]
    else:
        a[i] = T[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())

ans = 0
hands = []
for i in range(N):
    if i <= K - 1:
        # グー
        if T[i] == 'r':
            ans += P
            hands.append('p')
        # チョキ
        elif T[i] == 's':
            ans += R
            hands.append('r')
        # パー
        else:
            ans += S
            hands.append('s')
    else:
        if T[i] == 'r':
            if hands[i-K] != 'p':
                ans += P
                hands.append('p')
            else:
                if i + K <= N - 1:
                    hands.append(list(set('rsp') - set([T[i+K], hands[i-K]]))[0])
        # チョキ
        elif T[i] == 's':
            if hands[i-K] != 'r':
                ans += R
                hands.append('r')
            else:
                if i + K <= N - 1:
                    hands.append(list(set('rsp') - set([T[i+K], hands[i-K]]))[0])
        # パー
        else:
            if hands[i-K] != 's':
                ans += S
                hands.append('s')
            else:
                if i + K <= N - 1:
                    hands.append(list(set('rsp') - set([T[i+K], hands[i-K]]))[0])

print(ans)