Problem:


Score : 400 points

Problem Statement

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

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

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

R points for winning with Rock;

S points for winning with Scissors;

P points for winning with Paper.

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

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

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

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

Notes

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

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

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

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

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

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

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

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

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

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

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

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996



Sample input:
5 2
8 7 6
rsrpr


Sample output:
27

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = 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-K):
  if T[i] == 'r':
    if A[i-K] == 'p':
      if T[i+K] == 's':
        A.append('s')
      else:
        A.append('r')
      continue
    A.append('p')
    point += P
  elif T[i] == 's':
    if A[i-K] == 'r':
      if T[i+K] == 'p':
        A.append('p')
      else:
        A.append('s')
      continue
    A.append('r')
    point += R
  else:
    if A[i-K] == 's':
      if T[i+K] == 'r':
        A.append('r')
      else:
        A.append('p')
      continue
    A.append('s')
    point += S


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

Submission status: Accepted

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

for i in range(len(T)):
  if T[i] == "r":
    points.append(P)
  if T[i] == "s":
    points.append(R)
  if T[i] == "p":
    points.append(S)
  
  if i >= K and T[i] == T[i-K]:
    if points[i] > points[i-K]:
      points[i-K] = 0
    else:
      points[i] = 0

print(sum(points))

Submission status: Accepted

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

#print(t)

m={'r':'R','s':'S','p':'P'}
rot = {'R':'p','S':'r','P':'s'}
ans = t.translate(str.maketrans(m))
ans = ans.translate(str.maketrans(rot))
#print(ans)

#print('#####################')
val = 0
for i in range(k):
    #print(ans[i::k])#.replace('pp','pX').replace('ss','sX').replace('rr','rX'))
    tmp = (ans[i::k].replace('pp','pX').replace('ss','sX').replace('rr','rX'))
    val += tmp.count('r')*r + tmp.count('s')*s + tmp.count('p')*p


#result = ans.count('r')*r + ans.count('s')*s + ans.count('p')*p
#print('####################')
print(val)

Submission status: Accepted

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

if r >= s and s >= p:
    strong_list = ["r", "s", "p"]
    opp_list = ["s", "p", "r"]
    strong_list_num = [r, s, p]
elif r >= p and p >= s:
    strong_list = ["r", "p", "s"]
    opp_list = ["s", "r", "p"]
    strong_list_num = [r, p, s]
elif s >= p and p >= r:
    strong_list = ["s", "p", "r"]
    opp_list = ["p", "r", "s"]
    strong_list_num = [s, p, r]
elif s >= r and r >= p:
    strong_list = ["s", "r", "p"]
    opp_list = ["p", "s", "r"]
    strong_list_num = [s, r, p]
elif p >= r and r >= s:
    strong_list = ["p", "r", "s"]
    opp_list = ["r", "s", "p"]
    strong_list_num = [p, r, s]
else:
    strong_list = ["p", "s", "r"]
    opp_list = ["r", "p", "s"]
    strong_list_num = [p, s, r]

my_hands = [0] * n
sum = 0
for ct in range(3):
    my_current_hand = strong_list[ct]
    opp_current_hand = opp_list[ct]
    for i in range(n):
        if not t[i] == opp_current_hand:
            continue
        elif i-k < 0:
            my_hands[i] = my_current_hand
            sum += strong_list_num[ct]
        elif not my_hands[i-k] == my_current_hand:
            my_hands[i] = my_current_hand
            sum += strong_list_num[ct]
print(sum)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, k = LI()
    rsp = LI()
    t = S()
    dp = [[0] * 3 for i in range(n + k)]
    j = ["r", "s", "p"]
    for i in range(n):
        ti = t[i]
        for l in range(3):
            dp[i + k][l] = max(dp[i][(l - 1) % 3], dp[i][(l + 1) % 3]) + (rsp[l] if (j.index(ti) - 1) % 3 == l else 0)

    ans = 0
    for i in range(k):
        ans += max(dp[n + i])
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

ans = 0
check = {i:0 for i in range(N)}
for i in range(N):
    if i <= K-1:
        if T[i] == 'r':
            ans += P
        elif T[i] == 's':
            ans += R
        else:
            ans += S
    else:
        if T[i] != T[i-K]:
            if T[i] == 'r':
                ans += P
            elif T[i] == 's':
                ans += R
            else:
                ans += S
        elif T[i] == T[i-K] and check[i-K] == 1:
            if T[i] == 'r':
                ans += P
            elif T[i] == 's':
                ans += R   
            else:
                ans += S
        else:
            check[i] = 1

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int, input().split())
R,S,P=map(int, input().split()) 
T = list(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
 

for i in range(N-K):
    if(T[i] == T[i+K]):
        ten[i+K] = 0
        T[i+K] = 'o'


print(sum(ten))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ro,se,pe=map(int,input().split())
t=input()
cnt=0
x=[]
for i in range(n):
    if(i>=k):
        if(t[i]=='r' and x[i-k]!='p'):
            cnt=cnt+pe
            x.append('p')
        elif(t[i]=='s' and x[i-k]!='r'):
            cnt=cnt+ro
            x.append('r')
        elif(t[i]=='p' and x[i-k]!='s'):
            cnt=cnt+se
            x.append('s')
        else:
            x.append('n')
    else:
        if(t[i]=='r'):
            cnt=cnt+pe
            x.append('p')
        elif(t[i]=='s'):
            cnt=cnt+ro
            x.append('r')
        elif(t[i]=='p'):
            cnt=cnt+se
            x.append('s')
        else:
            x.append('n')
print(cnt)

Submission status: Accepted

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

def point(w):
    if w == 'r':
        return p
    elif w == 's':
        return r
    else:
        return s

total = 0
enable = [True for _ in range(n)]
for i in range(n):
    if enable[i]:
        #print(enable)
        total += point(t[i])
        if i+k < n and t[i] == t[i+k]:
            enable[i+k] = False

print(total)

Submission status: Accepted

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

for i in t:
  if i == "s":
    T.append(r)
  if i == "p":
    T.append(s)
  if i == "r":
    T.append(p)

ans = 0
for i in range(n):
  if i+k < n:
    if t[i] == t[i+k]:
      T[i+k] = 0
      t[i+k] = "q"
      ans += T[i]
    else:
      ans += T[i]
  else:
    ans += T[i]
print(ans)

Submission status: Accepted

Solution code:
# ABC149 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,k=nm()
r,s,p=nm()
t=si()
l=[[] for i in range(k)]
ans=0

for i in range(n):
    j=(i+1)%k
    l[j].append(t[i:i+1])

same_flg=False
for ll in l:
    cur_str=''
    for lll in ll:
        if cur_str=='':
            if lll=='p':
                ans+=s
            elif lll=='r':
                ans+=p
            elif lll=='s':
                ans+=r 
            cur_str=lll
            same_flg=True
            continue

        if lll==cur_str:
            # 足さない
            cur_str=lll
            if same_flg==True:
                same_flg=False
            elif same_flg==False:
                if lll=='p':
                    ans+=s
                elif lll=='r':
                    ans+=p
                elif lll=='s':
                    ans+=r 
                same_flg=True
            pass
        else:
            if lll=='p':
                ans+=s
            elif lll=='r':
                ans+=p
            elif lll=='s':
                ans+=r
            cur_str=lll
            same_flg=True
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
R,S,P=map(int,input().split())
get=[P,R,S]
t=list(input())
info=[]
for i in range(1,k+1): #グル＾プ分け
    a=[]
    num=i-1
    count=0
    while num<=(n-1):
        if t[num]=="r":
            b=0
        elif t[num]=="s":
            b=1
        else:
            b=2
        a.append(b)
        count+=1
        num+=k
    a.insert(0,count)
    info.append(a)
#print(info)
score=0
for i in range(k):
    if info[i][0]==1: #一個なら勝てばいい
        score+=get[info[i][1]]
        continue
    rensa=1
    now=info[i][1]
    for j in range(2,info[i][0]+1):
        if now==info[i][j]:
            rensa+=1
        else:
            if rensa%2==0: #偶数なら半分勝てる
                score+=((rensa//2)*get[now])
            else:
                score+=((rensa//2+1)*get[now])
            now=info[i][j]
            rensa=1
    if rensa==1:
        score+=get[now]
    else:
        if rensa%2==0: #偶数なら半分勝てる
                score+=((rensa//2)*get[now])
        else:
            score+=((rensa//2+1)*get[now])
print(score)

Submission status: Accepted

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

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

count = 0

for i in range(N):
  count += point[T[i]]

for i in range(K):
  S = [T[j] for j in range(i, N, K)]
  # print(S)
  same = 1
  for j in range(1, len(S)):
    # print((i, j, same))
    if S[j-1] == S[j]:
      same += 1
    else:
      t = point[S[j-1]] * (same // 2)
      # print(('!', same, t))
      count -= t
      same = 1
  if same >= 2:
    t = point[S[j-1]] * (same // 2)
    # print((same, t))
    count -= t
    same = 1

print(count)

Submission status: Accepted

Solution code:
import re
n,k=[int(i) for i in input().split()]
r,s,p=[int(i) for i in input().split()]
order=input()

ans=0
ans+=order.count("r")*p
ans+=order.count("s")*r
ans+=order.count("p")*s

for i in range(k):
    part=order[i::k]
    check=re.findall(r'r+r', part)
    if check:
        for hand in check:
            ans-=(len(hand)//2)*p
    check=re.findall(r's+s', part)
    if check:
        for hand in check:
            ans-=(len(hand)//2)*r
    check=re.findall(r'p+p', part)
    if check:
        for hand in check:
            ans-=(len(hand)//2)*s

print(ans)

Submission status: Accepted

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

d = {'R': R, 'S': S, 'P': P}

win = T.replace('r', 'P').replace('s', 'R').replace('p', 'S')

SUM = 0
flag = [True] * N
for i in range(N):
  if i < K:
    SUM += d[win[i]]
  else:
    if i >= K and win[i] == win[i-K]:
      if flag[i-K]:
        flag[i] = False
      else:
        SUM += d[win[i]]
    else:
      SUM += d[win[i]]

print(SUM)

Submission status: Accepted

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]
    count = 1
    length = len(L)
    for i in range(length):
        try:
            if L[i] == L[i+1]:
                count += 1
            else:
                score += point[L[i]]*((count+1)//2)
                count = 1
        except:
            score += point[L[i]]*((count+1)//2)
print(score)

Submission status: Accepted

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

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

score=0
mycard = []
for i in range(N):
    if i < K:
        score += getScore(T[i])
        mycard.append(1)
    else:
        if mycard[i-K] == 0:
            score += getScore(T[i])
            mycard.append(1)
        else:
            if T[i] != T[i-K]:
                score += getScore(T[i])
                mycard.append(1)
            else:
                mycard.append(0)
print(score)

Submission status: Accepted

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

a = {}
a["r"] = P
a["s"] = R
a["p"] = S

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

for i in range(N):
    if 0 <= (i - K):
        if T[i] == T[i - K]:
            if not temp[i-K]:
                ans -= a[T[i]]
                temp[i] = True

print(ans)

Submission status: Accepted

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

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] = [k for k in hands.keys() if k not in (t, hands[t])]
        else:
            memo[i] = hands[t]
            max_score += score[hands[t]]
            
print(max_score)

Submission status: Accepted

Solution code:
def func(u):
    if u=="r":
        return "p"
    elif u =="s":
        return "r"
    else:
        return "s"

def func1(memo):
    rcount = memo.count("r")
    pcount = memo.count("p")
    scount = memo.count("s")
    if rcount ==0:
        return "r"
    elif pcount == 0:
        return "p"
    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])
    memory1 = []
    memory1.append(te)
    hantei = True
    if i>=K:
        if te == memory[i-K]:
            if i+K<=N-1:
                te = T[i]
                memory1.append(te)
                te1 = func(T[i+K])
                if te1==te:
                    te = func1(memory1)
            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: Accepted

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
total = t.count('r')*p+t.count('s')*r+t.count('p')*s
for i in range(k,n):
  if t[i-k]==t[i]:
    if t[i]=='r':
      total-=p
      t[i]='x'
    elif t[i]=='s':
      total-=r
      t[i]='x'      
    elif t[i]=='p':
      total-=s
      t[i]='x'
print(total)

Submission status: Accepted

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

#r<p,s<r,p<s
flag = []
alls = 0
for i in range(N) :
    if i < K :
       flag.append(0)
       if T[i]=="r" : 
          alls += P
       elif T[i]=="s" :  
          alls += R
       else :  
          alls += S
    elif T[i]!=T[i-K] or ( T[i]==T[i-K] and flag[i%K] == 1 ):
       flag[i%K] = 0
       if T[i]=="r" : 
          alls += P
       elif T[i]=="s" :  
          alls += R
       else :  
          alls += S
    elif T[i]==T[i-K]:
       flag[i%K] = 1

print( alls )

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input().rstrip()
ret = 0
me = []
for i, rival in enumerate(t):
    if rival == 'r':
        if i - k >= 0 and me[i - k] == 'p':
            if i + k < n:
                if t[i + k] == 'p':
                    me.append('r')
                elif t[i + k] == 's':
                    me.append('s')
                elif t[i + k] == 'r':
                    me.append('s')
        else:
            me.append('p')
            ret += p
    elif rival == 's':
        if i - k >= 0 and me[i - k] == 'r':
            if i + k < n:
                if t[i + k] == 'r':
                    me.append('s')
                elif t[i + k] == 'p':
                    me.append('p')
                elif t[i + k] == 's':
                    me.append('s')
        else:
            me.append('r')
            ret += r
    elif rival == 'p':
        if i - k >= 0 and me[i - k] == 's':
            if i + k < n:
                if t[i + k] == 'r':
                    me.append('r')
                elif t[i + k] == 's':
                    me.append('p')
                elif t[i + k] == 'p':
                    me.append('r')
        else:
            me.append('s')
            ret += s
print(ret)

Submission status: Accepted

Solution code:
import math

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

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

ans=0
for i in range(k):
    l = [t[j] for j in range(i,n,k)]
    #print(l)
    m = len(l)
    tmp = 0
    cnt=1
    for j in range(m-1):
        if l[j]==l[j+1]:
            cnt+=1
        else:
            tmp+=math.ceil(cnt/2)*h(l[j])
            cnt=1
    tmp+=math.ceil(cnt/2)*h(l[m-1])
    #print(tmp)
    ans+=tmp
print(ans)

Submission status: Accepted

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

Solution code:
def ten(arr,R,S,P):
  ans = 0
  num = 0
  length = len(arr)
  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: Accepted

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

def cal(mozi, r, s, p):
    if mozi == "r":
        return r
    if mozi == "s":
        return s
    if mozi == "p":
        return p

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dasu_list = []
for i in range(0, k):
    dasu_list.append([])
for i in range(0, len(t)):
    j = i % k
    if t[i] == "r":
        dasu_list[j].append("p")
    if t[i] == "s":
        dasu_list[j].append("r")
    if t[i] == "p":
        dasu_list[j].append("s")
score = 0
for i in range(0, k):
    check_list = dasu_list[i]
    score += cal(check_list[0], r, s, p)
    for j in range(1, len(check_list) - 1):
        if check_list[j - 1] == check_list[j]:
            if check_list[j - 1] == "r":
                if check_list[j + 1] == "r":
                    check_list[j] = "s"
                if check_list[j + 1] == "s":
                    check_list[j] = "p"
                if check_list[j + 1] == "p":
                    check_list[j] = "s"
            if check_list[j - 1] == "s":
                if check_list[j + 1] == "r":
                    check_list[j] = "p"
                if check_list[j + 1] == "s":
                    check_list[j] = "p"
                if check_list[j + 1] == "p":
                    check_list[j] = "r"
            if check_list[j - 1] == "p":
                if check_list[j + 1] == "r":
                    check_list[j] = "s"
                if check_list[j + 1] == "s":
                    check_list[j] = "r"
                if check_list[j + 1] == "p":
                    check_list[j] = "r"
        else:
            score += cal(check_list[j], r, s, p)
    if check_list[len(check_list) - 2] != check_list[len(check_list) - 1]:
        score += cal(check_list[len(check_list) - 1], r, s, p)
print(score)

Submission status: Accepted

Solution code:
def main():
    n, k = [int(x) for x in input().split()]
    r, s, p = [int(x) for x in input().split()]
    points = {"r":p, "s":r, "p":s}
    flags = [True] * k
    t = input()
    score = 0
    # retstr = ""
    # retstr2 = ""
    for i in range(n):
        score += points[t[i]]
        # retstr2 += str(i % k)
        if not flags[i % k]:
            if t[i] == t[i - k]:
                flags[i % k] = True
                score -= points[t[i]]
                # retstr += "l"
            # else:
            #     retstr += "w"
        else:
            flags[i % k] = False
            # retstr += "w"
        # else:
        #     flags[i % k] = False
    # print(retstr2)
    # print(retstr)
    print(score)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
li = [int(i) for i in input().split()]
R = li[0]
S = li[1]
P = li[2]
Ta = input()
T = ['a'] * N
for i in range(N) :
    T[i] = Ta[i]
sum = 0
for i in range(N) :
    if i < N - K :
        if T[i] == "r" :
            if T[i+K] == "r" :
                T[i+K] = "k"
            sum+=P
        elif T[i] == "s" :
            if T[i+K] == "s" :
                T[i+K] = "k"
            sum+=R
        elif T[i] == "p" :
            if T[i+K] == "p" :
                T[i+K] = "k"
            sum+=S
        else :
            sum=sum
    else :
        if T[i] == "r" :
            sum+= P
        elif T[i] == "s" :
            sum+= R
        elif T[i] == "p" :
            sum+= S
        else :
            sum +=0
print(sum)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = input()
ans = 0
flag = [0 for _ in range(k)]
d = {"r":p, "s":r, "p":s}

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

for i in range(1, len(t)//k+1):
    if i == len(t)//k :
        for j in range(len(t)%k):
            if t[i*k+j] != t[(i-1)*k+j]:
                ans += d[t[i*k+j]]
                flag[j] = 0
            elif t[i*k+j] == t[(i-1)*k+j] and flag[j] == 0:
                flag[j] = 1
            elif t[i*k+j] == t[(i-1)*k+j] and flag[j] == 1:
                ans += d[t[i*k+j]]
                flag[j] = 0
    else:
        for j in range(k):
            if t[i*k+j] != t[(i-1)*k+j]:
                ans += d[t[i*k+j]]
                flag[j] = 0
            elif t[i*k+j] == t[(i-1)*k+j] and flag[j] == 0:
                flag[j] = 1
            elif t[i*k+j] == t[(i-1)*k+j] and flag[j] == 1:
                ans += d[t[i*k+j]]
                flag[j] = 0

print(ans)

Submission status: Accepted

Solution code:

def solve(N, K, R, S, P, T):
    hands = [None] * N
    score = {"r":P, "s":R, "p":S}

    for s in range(K):
        hands[s] = True # 最初は勝てる
        cont = 1

        # K ずつ増やす
        for i in range(s+K, N, K):
            if T[i] != T[i-K]:
                hands[i] = True
                cont = 1
            else:
                cont += 1
                if cont % 2 == 0:
                    hands[i] = False
                else:
                    hands[i] = True

    answer = 0
    #print(hands)
    for i in range(N):
        if hands[i]:
            #print(i, T[i], score[T[i]])
            answer += score[T[i]]
    return answer

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

print(solve(N, K, R, S, P, T))

Submission status: Accepted

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

l = []
for i in t:
    if i == "r":
        l.append("p")
    elif i == "s":
        l.append("r")
    else:
        l.append("s")
#print(l)
for i in range(k, n):
    if l[i] == l[i-k]:
        l[i] = "a"
#print(l)
for i in range(len(l)):
    if l[i] == "r":
        l[i] = r
    elif l[i] == "s":
        l[i] = s
    elif l[i] == "a":
        l[i] = 0
    else:
        l[i] = p
#print(l)
print(sum(l))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
add = [p, r, s]
rsp_str = ['r', 's', 'p']
t = input()
box = [None]*k
points = [None]*k

for i in range(k):
    box[i] = [rsp_str.index(str) for str in t[i::k]]

for i in range(k):
    prev = -1
    point = 0
    for hand in box[i]:
        if hand == prev:
            prev = -1
            continue
        point += add[hand]
        prev = hand
    points[i] = point

print(sum(points))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
R,S,P=map(int,input().split())
l=list(input())
play=[]

def point(hand):
    if hand=="r":
        return ["p",P]
    elif hand=="s":
        return ["r",R]
    else:
        return ["s",S]

ans=0
for i in range(N)[::-1]:
    if len(play)>=K:
        if point(l[i])[0]==play[-K]:
            if i-K>=0:
                temp=point(l[i-K])[0]
                for item in ["r","s","p"]:
                    if item!=play[-K] and item!=temp:
                        play.append(item)
                        break
            else:
                for item in ["r","s","p"]:
                    if item!=play[-K]:
                        play.append(item)
                        break
        else:
            play.append(point(l[i])[0])
            ans+=point(l[i])[1]
            
    else:
        play.append(point(l[i])[0])
        ans+=point(l[i])[1]
#print(play[::-1])
print(ans)

Submission status: Accepted

Solution code:
N, K  = map(int, input().split())
R, S, P  = map(int, input().split())
T = list(input())
Group = [[0]*0 for h in range(K)]
Ans = 0

for i in range(len(T)):
    L = i % K
    Group[L].append(T[i])

for i in range(K):
    A = Group[i][0]
    Bit = 0
    for j in range(len(Group[i])):
        if Group[i][j] == A and Bit == 0:
            Bit = 1
            A = Group[i][j]
            if Group[i][j] == "r":
                Ans += P
            elif Group[i][j] == "s":
                Ans += R
            else:
                Ans += S
        elif Group[i][j] == A and Bit == 1:
            Bit = 0
            A = Group[i][j]
        else :
            Bit = 1
            A = Group[i][j]
            if Group[i][j] == "r":
                Ans += P
            elif Group[i][j] == "s":
                Ans += R
            else:
                Ans += S
print(Ans)

Submission status: Accepted

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

RSP = input().split()
R = int(RSP[0])
S = int(RSP[1])
P = int(RSP[2])
tab = {'r':R, 's':S, 'p':P}
T = input()

from collections import defaultdict
counter = defaultdict(int)

if len(T) <= K:
  pass
else:
  ts = [T[i::K] for i in range(K)]
  for tt in ts:
    duplicate = True
    prev = tt[0]
    for t in tt[1:]:
      if prev == t:
        if duplicate:
          counter[t] += 1
          duplicate = False
        else:
          duplicate = True
      else:
        duplicate = True
      prev = t
score = (T.count('r')-counter['r'])*P\
+(T.count('s')-counter['s'])*R\
+(T.count('p')-counter['p'])*S
print(score)

Submission status: Accepted

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

pt = [0 for i in range(n)]

for i in range(n):
  if t[i] == "r":
    pt[i] = p
  elif t[i] == "s":
    pt[i] = r
  else:
    pt[i] = s
  if i >= k and t[i] == t[i - k] and pt[i - k] > 0:
    pt[i] = 0

print(sum(pt))