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:
def func(u):
    if u=="r":
        return "p"
    elif u =="s":
        return "r"
    else:
        return "s"


N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
score = 0
memory = []
for i in range(0,N):
    te = func(T[i])
    hantei = True
    if i>=K:
        if te == memory[i-K]:
            te = T[i]
            hantei = False

    if hantei == True:
        if te == "r":
            score+=R
        elif te == "s":
            score+=S
        else:
            score+=P
    memory.append(te)

print(score)

Submission status: Wrong Answer

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,k=MI()
    r,s,p=MI()
    t=S()
    ans=0
    ns=""
    for i in range(k):
        if t[i]=="r":
            ans+=p
            ns+="p"
        if t[i]=="p":
            ans+=s
            ns+="s"
        if t[i]=="s":
            ans+=r
            ns+="r"
    for i in range(k,n-k):
        # print(i,i+k,i-k,n-k,ns)
        if t[i]=="r" and ns[i-k]=="p" and t[i+k]=="s":
            ns+="s"
            ans+=0
        if t[i]=="r" and ns[i-k]=="p":
            ns+="r"
            ans+=0
        if t[i]=="r" and ns[i-k]!="p":
            ns+="p"
            ans+=p
        if t[i]=="p" and ns[i-k]=="s" and t[i+k]=="r":
            ns+="r"
            ans+=0
        if t[i]=="p" and ns[i-k]=="s":
            ns+="p"
            ans+=0
        if t[i]=="p" and ns[i-k]!="s":
            ns+="s"
            ans+=s
        if t[i]=="s" and ns[i-k]=="r" and t[i+k]=="p":
            ns+="p"
            ans+=0
        if t[i]=="s" and ns[i-k]=="r":
            ns+="s"
            ans+=0
        if t[i]=="s" and ns[i-k]!="r":
            ns+="r"
            ans+=r
    for i in range(n-k,n):
        if t[i]=="r" and ns[i-k]=="p":
            ns+="r"
            ans+=0
        if t[i]=="r" and ns[i-k]!="p":
            ns+="p"
            ans+=p
        if t[i]=="p" and ns[i-k]=="s":
            ns+="p"
            ans+=0
        if t[i]=="p" and ns[i-k]!="s":
            ns+="s"
            ans+=s
        if t[i]=="s" and ns[i-k]=="r":
            ns+="s"
            ans+=0
        if t[i]=="s" and ns[i-k]!="r":
            ns+="r"
            ans+=r
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def get_reward(x, r, s, p):
    if x == "r":
        return p
    if x == "s":
        return r
    if x == "p":
        return s


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


N, K = [int(i) for i in input().split(" ")]
R, S, P = [int(i) for i in input().split(" ")]
T = list(input())

total = 0

for i, x in enumerate(T):
    if i <= K-1 or T[i-K] != x:
        total += get_reward(x, R, S, P)
        continue
    if i >= K-1:
        T[i] = rotate(x)


print(total)

Submission status: Wrong Answer

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

result = 0
ans = []

for t in range(N) :
  if t < K :
    result += dic[T[t]]
    ans.append(ans_dic[T[t]])
  else :
    if ans[t-K] == ans_dic[T[t]] :
      ans.append(T[t])
    else :
      result += dic[T[t]]
      ans.append(ans_dic[T[t]])

print(result)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split(' ')))
R,S,P=list(map(int,input().split(' ')))
T=input()
y=0
total=0
for i in T:
    y=y+1
    if y-K<=0:
        if i=='r':
            total=total+P
        if i=='s':
            total=total+R
        if i=='p':
            total=total+S
    else:
        if i=='r' and (T[y-K]=='r' or T[y-K]=='s'):
            total=total+P
        else:
            total=total       
        if i=='s' and (T[y-K]=='s' or T[y-K]=='p'):
            total=total+R
        else:
            total=total
        if i=='p' and (T[y-K]=='p' or T[y-K]=='r'):
            total=total+S
        else:
            total=total
print(total)

Submission status: Wrong Answer

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

ans = [0] * n
def janken(te):
  if te == 'r':
    return p
  elif te == 's':
    return r
  else:
    return s
    
for i in range(n):
  konkai = janken(t[i])
  if i < k:
    ans[i] = konkai
  elif ans[i-k] != konkai:
    ans[i] = konkai
  else:
    ans[i] = 0

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
R,S,P = map(int,input().split())
t = input()
w= t.upper()
T = list(t)
WW = ''.join(w)
WW = WW.replace("R","p")
WW = WW.replace("S","r")
WW = WW.replace("P","s")
WW =WW.lower()
W = list(WW)

ans = 0


for i in range(len(W)):
    if W[i] == "r":
        ans += R
    elif W[i] == "s":
        ans += S
    else:
        ans += P

for i in range(n-k):
    if W[i] == W[i+k]:
        W[i+k] = T[i+k]
        if W[i] == "r":
            ans -= R
        elif W[i] == "s":
            ans -= S
        else:
            ans -= P
            
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
ans = 0
same_flag = 0
for i in range(N):
  if i < K: # K回目までは常に勝てる
    if T[i] == 'r':
      ans += P
    if T[i] == 's':
      ans += R
    if T[i] == 'p':
      ans += S
  else:
    if T[i] == T[i-K]: #K個前が同じ手
      if i >= 2*K:
        if T[i] == T[i-2*K]: #2K個前も同じ手なら，フラグをひっくり返す
          same_flag = 1-same_flag
        else:
          same_flag = 0
        if same_flag:
          if T[i] == 'r':
            ans += P
          if T[i] == 's':
            ans += R
          if T[i] == 'p':
            ans += S
      else:
        same_flag = 0
    else:
      same_flag = 0
      if T[i] == 'r':
        ans += P
      if T[i] == 's':
        ans += R
      if T[i] == 'p':
        ans += S

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
flag=1
R,S,P=map(int,input().split())
total=0
T=input()
count=0
for i in range(N):
    if T[i]=='r':
        total+=P
    if T[i]=='s':
        total+=R
    if T[i]=='p':
        total+=S
for k in range(K):
    for i in range(count,N,K):
        if T[i-K]==T[i] and flag==1:
            if T[i] == 'r':
                total -= P
            if T[i] == 's':
                total -= R
            if T[i] == 'p':
                total -= S

            flag=0
        else:
            flag=1
    count+=1
print(total)

Submission status: Wrong Answer

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

te = ['r', 's', 'p']

def win(s):
	if s == 'r':
		return 2
	elif s == 's':
		return 0
	else:
		return 1

taka = []
cnt = 0

for i in range(n):
	winner = win(t[i])
	if i < k:
		taka.append(te[winner])
		cnt += rsp[winner]
	else:
		if taka[i-k] == te[winner]:
			if i < n-k:
				next = win(t[i+k])
				can = ['r', 's', 'p']
				del can[winner]
				if next in can:
					can = can.remove(next)
					taka.append(can)
				else:
					taka.append(can[0])
			else:
				can = ['r', 's', 'p']
				del can[winner]
				taka.append(can[0])
		else:
			taka.append(te[winner])
			cnt += rsp[winner]
print(cnt)

Submission status: Wrong Answer

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

win={"r":"p","s":"r","p":"s"}
score={"r":r,"s":s,"p":p}
total=0
already=[]
for i in range(k):
    win_hand=win[tl[i]]
    already.append(win_hand)
    total+=score[win_hand]
temp=["r","s","p"]
for j in range(k,n):
    temp=["r","s","p"]
    win_hand=win[tl[j]]
    print(j-k)
    if already[j-k]==win_hand:
        temp.remove(win_hand)
        if j+k <= n-1:
            keep=win[tl[j+k]]
            if not keep in temp:
                already.append(temp[0])
            else:
                temp.remove(keep)
                already.append(temp[0])
        else:
            already.append(temp[0])
        pass
    else:
        already.append(win_hand)
        total+=score[win_hand]
print(total)

Submission status: Wrong Answer

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

ans = []
for idx, t in enumerate(T):
    if t == 'r':
            ans.append(P)
    elif t == 's':
            ans.append(R)
    elif t == 'p':
            ans.append(S)

for i in range(N-K):
    if ans[i] == ans[i+K]:
        ans[i+K] = 0

print(sum(ans))

Submission status: Wrong Answer

Solution code:
(N, K), *D, = [s.split() for s in open(0)]
points = 0
dd = {r: p for p, r in zip(list(map(int, D[0])), ["s", "p", "r"])}
records = []
for i in range(len(D[1][0])):
    if i < int(K):
        points += dd[D[1][0][i]]
        records.append(D[1][0][i])
    else:
        if dd[D[1][0][i]] == dd[D[1][0][i-int(K)]] and records[i-int(K)] == "pass":
            points += dd[D[1][0][i]]
            records.append(D[1][0][i])
        elif dd[D[1][0][i]] == dd[D[1][0][i-int(K)]] and records[i-int(K)] != "pass":
             records.append("pass")
        else:
            points += dd[D[1][0][i]]
            records.append(D[1][0][i])
            
print(points)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
def score(c):
    if c=='r':
        return p
    if c=='s':
        return r
    if c=='p':
        return s

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

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split()) 
R,S,P=map(int, input().split()) 
T = input()
 
ten = [0] * N
for i in range(N):
    if (T[i] == 'r'):
        ten[i] = P
    elif(T[i] == 's'):
        ten[i] = R
    else:
        ten[i] = S
 
ten2 = ten[:]
for i in range(N-K):
    if(ten[i] == ten[i+K]):
        ten[i+K] = 0
for i in range(N-1,K-1,-1):
    if(ten2[i] == ten2[i-K]):
        ten2[i-K] = 0

print(max(sum(ten),sum(ten2)))

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

hands = {'r': 'p', 's': 'r', 'p': 's'}
score = {'r': R, 's': S, 'p': P}
max_score = 0
memo = [None for _ in range(N)]

for i, t in enumerate(T):
    if i < K:
        memo[i] = hands[t]
        max_score += score[hands[t]]
    else:
        if memo[i-K] == hands[t]:
            memo[i] = t
        else:
            memo[i] = hands[t]
            max_score += score[hands[t]]
            
print(max_score)

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(K):
    L.append(T[i::K])
#print(L)

def Point(List):
    rr,ss,pp=1,1,1
    point=0
    if List[0]=='r':
        point+=P
    elif List[0]=='s':
        point+=R
    else:
        point+=S
    for i in range(1,len(List)):
        cur,past=List[i],List[i-1]
        if cur!=past:
            if cur=='r':
                point+=P
            elif cur=='s':
                point+=R
            else:
                point+=S
        else:
            if cur=='r':
                rr=not(rr)
                if rr:
                    point+=P
            elif cur=='s':
                ss=not(ss)
                if ss:
                    point+=R
            elif cur=='p':
                pp=not(pp)
                if pp:
                    point+=S
    return point

M=0
for i in L:
    M+=Point(i)

print(M)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k=map(int,readline().split())
r,s,p=map(int,readline().split()) #gu cyoki pa
t=input()
dic={'r':p,'s':r,'p':s}
dic2={'r':['p','r'],'s':['r','s'],'p':['s','p']}
h=''

c=0
for i in range(k):
  c+=dic[t[i]]
  h+=dic2[t[i]][0]
for i in range(k,n):
  if h[i-k]!=dic2[t[i]][0]:
      c+=dic[t[i]]
      h+=dic2[t[i]][0]
  else:
    h+=t[i]
print(c)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
_t = input()
patterns = ["p" if x == "r" else "r" if x == "s" else "s" for x in _t]
scores = [p if x == "r" else r if x == "s" else s for x in _t]
for i in range(n):
    if i > k - 1:
        if patterns[i - k] == patterns[i]:
            patterns[i] = _t[i]
            scores[i] = 0
print(sum(scores))

Submission status: Wrong Answer

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

hands = [None] * N
d1 = {'r': 'p', 's': 'r', 'p': 's'}
d2 = {'r': P, 's': R, 'p': S}
result = 0
for i in range(len(T)):
    if i >= K and d1[T[i]] == hands[i - K]:
        hands[i] = T[i]
    else:
        hands[i] = d1[T[i]]
        result += d2[T[i]]
print(result)

Submission status: Wrong Answer

Solution code:
def points(me, you, R, S, P):
    hand_map = {
        'r':'p',
        's':'r',
        'p':'s'
    }
    if hand_map[you] == me:
        if me == 'r':
            return R
        elif me =='p':
            return P
        elif me =='s':
            return S
    else:
        return 0
    
def main():
    N, K = list(map(int, input().split()))
    R, S, P = list(map(int, input().split()))
    T = input()
    Ts = list(T)

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

    memo = []
    cum = 0
    for i, t in enumerate(Ts):
        hand = hand_map[t]
        
        if i >= K:
            if hand == memo[i - K]:
                hand = t

        memo.append(hand)
        cum += points(hand, t, R,S,P)
        # print(cum, i, t, memo)


    print(cum)

if __name__ == "__main__":
    main()

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()
ans = 0
x = []
for i in range(n):
  if i<k:
    if t[i] == "r":
      x.append(0)
      ans += p
    elif t[i] == "s":
      x.append("r")
      ans += r
    elif t[i] == "p":
      x.append("s")
      ans += s
  else:
    if t[i] == "r":
      if x[i-k] != "p":
        x.append("p")
        ans += p
      else:
        x.append(-1)
    elif t[i] == "s":
      if x[i-k] != "r":
        x.append("r")
        ans += r
      else:
        x.append(-1)
    elif t[i] == "p":
      if x[i-k] != "s":
        x.append("s")
        ans += s
      else:
        x.append(-1)
print(ans)

Submission status: Wrong Answer

Solution code:

n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()
ans = 0
flag = 0
d = {"r":p, "s":r, "p":s}
for idx, j in enumerate(t):
    if idx >= k:
        if j != t[idx-k]:
            ans += d[j]
            flag = 0
        elif j == t[idx-k] and flag == 0:
            flag = 1
        elif j == t[idx-k] and flag == 1:
            ans += d[j]
            flag = 0         
    else:
        ans += d[j]
print(ans)

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

Submission status: Wrong Answer

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

# r...グー s..チョキ p...パー
tp = [0] * (n + 1)
ans = 0
for i in range(k):
    if t[i] == 'r':
        tp[i] = 'p'
        ans += p
    elif t[i] == 's':
        tp[i] = 'r'
        ans += r
    else:
        tp[i] = 's'
        ans += s

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

Submission status: Wrong Answer

Solution code:
tmp = input().split()
N = int(tmp[0])
K = int(tmp[1])
tmp = input().split()
R = int(tmp[0])
S = int(tmp[1])
P = int(tmp[2])
T = input()

history = []
ans = 0
for i in range(N):

    if not(len(history) > K-1):
        if T[i] == "r":
            ans += P
            history.append("P")
        elif T[i] == "s":
            ans += R
            history.append("R")
        else:
            ans += S
            history.append("S")
    
    else:
        if T[i] == "r":
            if history[i-K] == "P":
                history.append("R")
            else:
                ans += P
                history.append("P")
        elif T[i] == "s":
            if history[i-K] == "R":
                history.append("S")
            else:
                ans += R
                history.append("R")
        else:
            if history[i-K] == "S":
                history.append("P")
            else:
                ans += S
                history.append("S")
    # print(history)

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
List = [[] for k in range(K)]
for n in range(N):
    List[n % K].append(T[n])

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

score = 0
for k in range(K):
    L = List[k]
    choice = ['r', 's', 'p']
    for hand in L:
        if hand not in choice:
            choice = ['r', 's', 'p']
        else:
            score += point[hand]
            choice.remove(hand)
print(score)

Submission status: Wrong Answer

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

ans = 0
for i in range(k):
    t2 = ""
    j = 0
    while i + j * k <= n-1:
        t2 += t[i+j*k]
        j += 1
    m = len(t2)
    dp = [[0, 0, 0] for _ in range(m+1)]
    for x in range(m):
        for y in range(3):
            for z in range(3):
                if y != z:
                    if z == 0 and t2[x] == 'r':
                        dp[x+1][z] = dp[x][y] + score[z]
                    if z == 1 and t2[x] == 's':
                        dp[x+1][z] = dp[x][y] + score[z]
                    if z == 2 and t2[x] == 'p':
                        dp[x+1][z] = dp[x][y] + score[z]
                dp[x+1][z] = max(dp[x+1][z], dp[x][y])
    num = 0
    for z in range(3):
        num = max(num, dp[m][z])
    ans += num

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n, k = map(int, sys.stdin.readline().split())
r, s, p = map(int, sys.stdin.readline().split())
t = sys.stdin.readline().rstrip()
point = dict([('r', r), ('s', s), ('p', p)])

def hand(opponent):
    if opponent == 'r':
        return 'p'
    elif opponent == 's':
        return 'r'
    elif opponent == 'p':
        return 's'

def main():
    res = 0
    for i in range(k):
        cur = hand(t[i])
        res += point[cur]
        prev = cur
        for j in range(i+k, n, k):
            cur = hand(t[j])
            if cur == prev:
                cur = t[j]
            else:
                res += point[cur]
            prev = cur
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
N, K = raw_input().split()
N, K = int(N), int(K)

R, S, P = raw_input().split()
R, S, P = int(R), int(S), int(P) 

T = raw_input()

his = list()
ret = 0

for i in range(N):
    if T[i] == 'r':
        if i-K >= 0 and his[i-K] == 'p':
            his.append('r')
        else:
            ret += P
            his.append('p')

    elif T[i] == 's':
        if i-K >= 0 and his[i-K] == 'r':
            his.append('s')
        else:
            ret += R
            his.append('r')

    else: # T[i] == 'p'
        if i-K >= 0 and his[i-K] == 's':
            his.append('p')
        else:
            ret += S
            his.append('s')
    
print '{}'.format(ret)

Submission status: Wrong Answer

Solution code:
# print('input >>')

N, K = map(int,(input().split()))
r, s, p = map(int,(input().split()))
T = input()

point = 0

my = []

for i in range(K):
    if T[i] == 'r': # グーなら
        point += p # パー出す
        my.append('p')
    elif T[i] == 's': # チョキなら
        point += r # グー出す
        my.append('r')
    elif T[i] == 'p': # パーなら
        point += s # チョキだす
        my.append('s')

# 縛り以降
for i in range(K, len(T)):
    if T[i] == 'r': # グーなら
        if not my[i-K] == 'p': # パーが出せるなら
            point += p
            my.append('p')
        else:
            my.append('r')
    if T[i] == 's': # チョキなら
        if not my[i-K] == 'r': # グーが出せるなら
            point += r
            my.append('r')
        else:
            my.append('s')
    if T[i] == 'p': # パーなら
        if not my[i-K] == 's': # チョキが出せるなら
            point += s
            my.append('s')
        else:
            my.append('p')


# print('-----output-----')
print(point)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

ans = 0
for i in range(K):
    tmp = 1
    for j in range(i+K, N, K):
        if T[j] == T[j-K]:
            tmp += 1
        else:
            tmp = -(-tmp // 2)
            if T[j-K] == "r":
                tmp *= P
            elif T[j-K] == "s":
                tmp *= R
            else:
                tmp *= S
            ans += tmp
            tmp = 1

        if j + K >= N:
            tmp = -(-tmp // 2)
            if T[j] == "r":
                tmp *= P
            elif T[j] == "s":
                tmp *= R
            else:
                tmp *= S
            ans += tmp
    if i + K >= N:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def win(char):
    if char=="r":
        return "p"
    if char=="s":
        return "r"
    return "s"
n,k = [int(i)for i in input().split()]
r,s,p = [int(i)for i in input().split()]
word = input()
new = ""
total = 0
for pos in range(k):
    ans = win(word[pos])
    new+=ans
    if ans=="r":
        total+=r
    elif ans=="s":
        total+=s
    else:
        total+=p
cnt = 0
for pos in range(k,n):
    val = word[pos]
    ans = win(word[pos])
    if new[pos-k]==ans:
        new+=word[pos]
        cnt+=1
    else:
        new+=ans
        if ans=="r":
            total+=r
        elif ans=="s":
            total+=s
        else:
            total+=p
print(total)

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:
# coding: utf-8
n, k = [int(x) for x in input().split(" ")]
r, s, p = [int(x) for x in input().split(" ")]
t = input()
# print(t)
ans = []
point = {"g":r, "s":s, "p":p, ".":0}
for i in range(n):
    if t[i] == "r":
        ans += "p"
    elif t[i] == "s":
        ans += "g"
    elif t[i] == "p":
        ans += "s"
ret = 0
# print(ans)
for i in range(n-k-1):
    if ans[i] == ans[i+k]:
        ans[i+k] = "."
for x in ans:
    ret += point[x]
print(ret)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()
    m = ''
    e = 0

    for i in range(len(t)):
        if t[i] == 'r':
            if i >= k and m[i - k] == 'p':
                m += 'r'
            else:
                m += 'p'
                e += p
        elif t[i] == 's':
            if i >= k and m[i - k] == 'r':
                m += 's'
            else:
                m += 'r'
                e += r
        elif t[i] == 'p':
            if i >= k and m[i - k] == 's':
                m += 'p'
            else:
                m += 's'
                e += s
        else:
            assert False

    print(e)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(N):
    if i >= K-1:
        if T[i-K] == T[i]:
            T = T[:i] + 'z' + T[i+1:]
            
        else:
            count += dicta[T[i]]
    else:
        count += dicta[T[i]]
print(count)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N,K = map(int,input().split(' '))
r,s,p = map(int,input().split(' '))
S = list(input())
ANS = [None]*N

ans = 0
for i in range(K):
    k = S[i]
    if 'r' == k:
        ans += p
        ANS[i] = p
    elif 's' == k:
        ans += r
        ANS[i] = r
    else:
        ans += s
        ANS[i] = s

for j in range(K,N):
    k = S[j]
    pre = ANS[j-K]
    if 'r' == k:
        if p==pre:
            ANS[j] = 0
        else:
            ans += p
            ANS[j] = p
    elif 's' == k:
        if r==pre:
            ANS[j] = 0
        else:
            ans += r
            ANS[j] = r
    else:
        if s==pre:
            ANS[j] = 0
        else:
            ans += s
            ANS[j] = s
print(ans)