Problem:


Score : 400 points

Problem Statement

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

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

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

R points for winning with Rock;

S points for winning with Scissors;

P points for winning with Paper.

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

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

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

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

Notes

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

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

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

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

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

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

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

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

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

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

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

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996



Sample input:
5 2
8 7 6
rsrpr


Sample output:
27

Submission status: Wrong Answer

Solution code:
N,K = 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:
        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())
T = input()
h = {'s': 'r', 'p': 's', 'r': 'p'}
t = {'r': R, 's': S, 'p': P}

l = [[] for i in range(K)]
ans = 0
for i in range(N):
    k = i % K
    if len(l[k]) == 0:
        l[k].append(h[T[i]])
        ans += t[h[T[i]]]
    else:
        if l[k][-1] == h[T[i]]:
            l[k].append(T[i])
        else:
            l[k].append(h[T[i]])
            ans += t[h[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()

score = 0

a = 0
b = 0
c = 0

for i in range(K):
  if T[i] == "r" :
    score += P
  elif T[i] == "s":
    score += R
  elif T[i] == "p":
    score += S

for i in range(K,N):
  if T[i] == T[i - K]:
    if T[i] == "r":
      a += 1
    elif T[i] == "s":
      b += 1
    elif T[i] == "p":
      c += 1
  if T[i] == "r" and a % 2 == 0:
    score += P
  elif T[i] == "s" and b % 2 == 0:
    score += R
  elif T[i] == "p" and c % 2 == 0:
    score += S

print(score)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    cost = defaultdict(int)
    cost["r"] = p
    cost["s"] = r
    cost["p"] = s
    t = list(input())

    ans = 0
    for i in range(k):
        c = 0
        for j in range(i, n - k, k):
            if t[j] == t[j + k]:
                ans += cost[t[j]]
                t[j+k] = "ggg"
            else:
                ans += cost[t[j]]
        if t[j+k] != "ggg":
            ans += cost[t[j+k]]
    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()
score=0
te=[]
www='w'
for a in range(n):
  if a-k>=0and'prs'['rsp'.index(t[a])]==te[0]:
    te+=t[a]#;print('あいこ')
  else:
    score+=[p,r,s]['rsp'.index(t[a])]#;print('prs'['rsp'.index(t[a])],'勝ち')
    te+=['prs'['rsp'.index(t[a])]]
  if a-k>=0:
    del te[0]
print(score)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    cost = defaultdict(int)
    cost["r"] = p
    cost["s"] = r
    cost["p"] = s
    t = list(input())

    ans = 0
    for i in range(k):
        c = 0
        for j in range(i, n - k, k):
            if t[j] == t[j + k]:
                ans += cost[t[j]]
                t[j+k] = "ggg"
            else:
                ans += cost[t[j]]
        if t[j + k] != t[j] and t[j+k] != "ggg":
            ans += cost[t[j+k]]
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
ro, sc ,pa = map(int,input().split())
a = input()
dict = {'r':'p', 's':'r', 'p': 's'}
scores = {'r':ro,'s':sc,'p':pa}
can_lelect = 'rsp'
select = ['' for _ in range(n)]
cant = [[] for _ in range(n)]
left = 0
cur = k
while cur < n:
    need_cur = dict[a[cur]]
    need_left = dict[a[left]]
    if select[left] == '':
        select[left] = need_left
    if need_cur == select[left] :
        if select[left] != need_left:
            cant[left].append(need_cur)
            for v in can_lelect:
                if v not in cant[left]:
                    select[left] = v
                    break
            select[cur] = need_cur
        else:
            cant[cur].append(need_cur)
            for v in can_lelect:
                if  v not in cant[cur]:
                    select[cur] = v
                    break
    else:
        select[cur] = need_cur
    left+=1
    cur +=1
total = 0
for i in range(n):
    c = select[i]
    if c == dict[a[i]]:
        total+=scores[c]
print(total)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
for i in range(N):
    if T[i]=='r':
        T[i]=P
    elif T[i]=='s':
        T[i]=R
    else:
        T[i]=S

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

for i in range(K,N):
    if T[i]!=T[i-K]:
        ans+=T[i]
    else:
        T[i]=0
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
score=0
te=[]
www='w'
for a in range(n):
  if a-k>=0:
    if 'prs'['rsp'.index(t[a])]!=te[0]:
      score+=[p,r,s]['rsp'.index(t[a])]#;print('prs'['rsp'.index(t[a])],'勝ち')
      te+=['prs'['rsp'.index(t[a])]]
    else:
      te+=t[a]#;print('あいこ')
    del te[0]
  else:
    score+=[p,r,s]['rsp'.index(t[a])]#;print('prs'['rsp'.index(t[a])],'勝ち')
    te+=['prs'['rsp'.index(t[a])]]
print(score)
#prrsp

Submission status: Wrong Answer

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

R, S, P = [], [], []

for i, shape in enumerate(t):
  try:
    if (shape == "r") and (i - R[-1] != k):
      R.append(i)
    if (shape == "s") and (i - S[-1] != k):
      S.append(i)
    if (shape == "p") and (i - P[-1] != k):
      P.append(i)
  except IndexError:
    if (shape == "r"):
      R.append(i)
    if (shape == "s"):
      S.append(i)
    if (shape == "p"):
      P.append(i)
#  print(R, S, P)
a = len(R)
b = len(S)
c = len(P)
print(a*p + b*r + c*s)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    R, S, P = (int(i) for i in input().split())
    T = input()
    dp = [[0 for _ in range(N+1)] for _ in range(3)]
    pre = []
    for i, t in enumerate(T):
        if t == "r":
            dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
            dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
            dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + P
        elif t == "s":
            dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + R
            dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
            dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
        elif t == "p":
            dp[0][i+1] = max(dp[0][i], dp[1][i], dp[2][i])
            dp[1][i+1] = max(dp[0][i], dp[1][i], dp[2][i]) + S
            dp[2][i+1] = max(dp[0][i], dp[1][i], dp[2][i])

        if K <= i:
            dp[pre[-K]][i+1] = 0

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


if __name__ == '__main__':
    main()

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) < k:
        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'))
print(cand)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    cost = defaultdict(int)
    cost["r"] = p
    cost["s"] = r
    cost["p"] = s
    t = list(input())

    ans = 0
    for i in range(k):
        c = 0
        for j in range(i, n - k, k):
            if t[j] == "ggg":
                continue
            if t[j] == t[j + k]:
                ans += cost[t[j]]
                t[j+k] = "ggg"
            else:
                ans += cost[t[j]]
        if t[j + k] != t[j]:
            ans += cost[t[j+k]]
    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())
scores = {"r":p,"s":r,"p":s}
T = input()
import numpy as np
subT = [""] * k
for i in range(n):
    ind = i % k 
    subT[ind] += T[i]

ans = 0
for S in subT:
    cnt = 0
    prev = "0"
    for i, s in enumerate(S):
        if i == 0:
            ans += scores[s]
        elif prev == s:
                cnt += 1
                if cnt == 2:
                    ans += scores[s]
                    cnt = 0
        else:
            ans += scores[s]
        prev = s
        

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
ro, sc ,pa = map(int,input().split())
a = input()
dict = {'r':'p', 's':'r', 'p': 's'}
scores = {'r':ro,'s':sc,'p':pa}
can_lelect = 'rsp'
select = ['' for _ in range(n)]
cant = [[] for _ in range(n)]
left = 0
cur = k
while cur < n:
    need_cur = dict[a[cur]]
    need_left = dict[a[left]]
    if select[left] == '':
        select[left] = need_left
    if need_cur == need_left:
        if select[left] != need_left:
            for v in can_lelect:
                if v != select[left] and v not in cant[left]:
                    select[left] = v
                    break
            select[cur] = need_cur
        else:
            cant[cur].append(need_cur)
            for v in can_lelect:
                if v != select[cur] and v not in cant[cur]:
                    select[cur] = v
                    break
    else:
        select[cur] = need_cur
    left+=1
    cur +=1
total = 0
for i in range(n):
    c = select[i]
    if c == dict[a[i]]:
        total+=scores[c]
print(total)

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

    def play(com, player):
        if com == 'r' and player == 'p':
            return P
        elif com == 's' and player == 'r':
            return R
        elif com == 'p' and player == 's':
            return S
        else:
            return 0

    score = 0
    for n in range(N):
        if n <= K:
            score += max(play(T[n], 'r'), play(T[n], 's'), play(T[n], 'p'))
        else:
            if T[n - K] == T[n]:
                score += 0
            else:
                score += max(play(T[n], 'r'), play(T[n], 's'), play(T[n], 'p'))

    print(score)


main()

Submission status: Wrong Answer

Solution code:
num = input().split(' ')
point = input().split(' ')
point_int = [int(point[i]) for i in range(3)]
data = input()
count = 1
result = 0
judge = [0 for i in range(int(num[0]))]
for i in range(int(num[0])):
    if(data[i] == 'r'):
        if(i - int(num[1]) >= 0):
            if(data[i - int(num[1])] == 'r'):
                if(judge[i - int(num[1])] == 0):
                    result += point_int[2]
                    judge[i] = 1
                else:
                    pass

            else:
                result += point_int[2]
                judge[i] = 1
        else:
            result += point_int[2]
            judge[i] = 1
    elif(data[i] == 's'):
        if(i - int(num[1]) >= 0):
            if(data[i - int(num[1])] == 's'):
                if(judge[i - int(num[1])] == 0):
                    result += point_int[0]
                    judge[i] = 1
                else:
                    pass
            else:
                result += point_int[0]
                judge[i] = 1
        else:
            result += point_int[0]
            judge[i] = 1

    else:
        if(i - int(num[1]) >= 0):
            if(data[i - int(num[1])] == 'p'):
                if(judge[i - int(num[1])] == 0):
                    result += point_int[1]
                    judge[i] = 1
                else:
                    pass
            else:
                result += point_int[1]
                judge[i] = 1
        else:
            result += point_int[1]
            judge[i] = 1
    print(result)

print(result)

Submission status: Wrong Answer

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

def battle(d, h):
    computer = T[d]
    if computer == 'r' and h == 2:
        return P
    if computer == 's' and h == 0:
        return R
    if computer == 'p' and h == 1:
        return S
    return 0


dp = [[0 for _ in range(3)] for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        if i - K >= 0:
            hands_b = dp[i-K+1]
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + battle(i, j))
        else:
            dp[i+1][j] = dp[i][j] + battle(i, j)

print(max(dp[i+1]))

Submission status: Wrong Answer

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

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

print(score)

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])
            else:
                hands.append(lose[s])
print(ans)

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):
    if K != 1:
        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()

turn = 0
score = 0
choice = ["r", "s", "p"]
score_dic = {}
score_dic["r"] = r
score_dic["s"] = s
score_dic["p"] = p

log = {}
for i in range(1, n):
    if turn <= k:
        game = t[i]
        if game == "r":
            log[i] = "p"
            score += p 
        elif game == "s":
            score += r
            log[i] = "r"
        else:
            score += s
            log[i] = "s"

    else:
        game = t[i]
        log_choice = log[i-k]
        cad_hand = ""
        cad_getscore = 0
        for choice_can in choice:
            if choice_can == log_choice:
                pass
            else:
                cad_score = score_dic[choice_can]
                if cad_score > cad_getscore:
                    cad_getscore = cad_score
                    cad_hand = choice_can
        score += cad_getscore
        log[i] = cad_hand
    
print(score)

Submission status: Wrong Answer

Solution code:
def getInput(string):
    return [int(ele)for ele in string.split(' ')]

roundOfPlay = input()
n,k = getInput(roundOfPlay)
score = input()
r,s,p = getInput(score)

t = input()

win ={
    "r":("p",p),
    "s":('r',r),
    "p":('s',s),
}

draw={
    'r':('r',0),
    's':('s',0),
    'p':('p',0)
}

lose={
    'r':('s',0),
    's':('p',0),
    'p':('r',0)
}
storeScore = 0
score = 0
storeHand =[]
hand = ""
for i,ele in enumerate(t):
    index = i - k 
    if index > 0:
        hand,score = win[ele]
        if hand == storeHand[index]:
            hand,score = draw[ele]
            if hand == storeHand[index]:
                hand,score = lose[ele]
                storeHand.append(hand)
            else:
                storeHand.append(hand)
        else:
            hand,score = win[ele]
            storeHand.append(hand)

            
    else:
        hand,score = win[ele]
        storeHand.append(hand)

    storeScore += score

print(storeScore)

Submission status: Wrong Answer

Solution code:
def janken(letter, index):
    t = T
    if index < K:
        if letter == 'r':
            return R
        elif letter == 's':
            return S
        elif letter == 'p':
            return P
    else:
        if T[index - K] == letter:
            return 0
        else:
            if letter == 'r':
                return R
            elif letter == 's':
                return S
            elif letter == 'p':
                return P

s = input().split()
N = int(s[0])
K = int(s[1])
score = input().split()
R = int(score[0])
S = int(score[1])
P = int(score[2])
T = input()
result = 0
for i in range(len(T)):
    result = result + janken(T[i], i)
print(result)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
r,s,p = input().split()
t = input()
t = t.replace('r', p).replace('s', r).replace('p', s)
ans = sum([int(s) for s in t[:k]])
for i in range(k,len(t)):
    if t[i-k] == t[i]:
        t = t[:i] + ('0') + t[i+1:]
    ans += int(t[i])
print(ans)

Submission status: Wrong Answer

Solution code:
[n, k] = map(int, input().split())
[r_point, s_point, p_point] = map(int, input().split())
machine = input()
winning = {
  'r' : 'p',
  's' : 'r',
  'p' : 's'
}
points = {
  'r': r_point,
  's': s_point,
  'p': p_point
}
player = ''
res = 0
for i, hand in enumerate(machine):
  win = winning[hand]
  if i-k>=0:
    player += win if player[i-k] != win else hand
  else:
    player += win

for p_hand, r_hand in zip(machine, player):
  if p_hand != r_hand:
    res += points[p_hand]

print(res)

Submission status: Wrong Answer

Solution code:
line1 = input().split(' ')
line2 = input().split(' ')
N = int(line1[0])
K = int(line1[1])
R = int(line2[0])
S = int(line2[1])
P = int(line2[2])
T = input()
score = 0
mem = list(range(K))

for i in range(N):
  index = i % K

  if (mem[index] != T[i:i+1]):
    if (T[i:i+1] == 'r'):
      score = score + R
    elif (T[i:i+1] == 's'):
      score = score + S
    elif (T[i:i+1] == 'p'):
      score = score + P
    mem[index] = T[i:i+1]
  else:
    mem[index] = 0

print(score)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 149 : D (2019/12/29)
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = str(input())
A = []
for i in range(N):
    if T[i] == 'r':
        A.append('p')
    elif T[i] == 's':
        A.append('r')
    elif T[i] == 'p':
        A.append('s')
#print('T={}'.format(T))
#print('j={}, A={}'.format(0, A))
for j in range(K, N):
    if A[j-K] == A[j]:
        if j+K < N:
            if A[j] == A[j+K]:
                if A[j] == 'r':
                    A[j] = 'p'
                elif A[j] == 's':
                    A[j] = 'p'
                elif A[j] == 'p':
                    A[j] = 'r'
            else:
                if A[j] == 'r' and A[j+K] == 's':
                    print('a',j,A[j],end=' ')
                    A[j] = 'p'
                    print(A[j])
                elif A[j] == 'r' and A[j+K] == 'p':
                    A[j] = 's'
                elif A[j] == 's' and A[j+K] == 'p':
                    A[j] = 'r'
                elif A[j] == 's' and A[j+K] == 'r':
                    A[j] = 'p'
                elif A[j] == 'p' and A[j+K] == 'r':
                    A[j] = 's'
                elif A[j] == 'p' and A[j+K] == 's':
                    A[j] = 'r'
        else:
            if A[j] == 'r':
                A[j] = 's'
            elif A[j] == 's':
                A[j] = 'p'
            elif A[j] == 'p':
                A[j] = 'r'
    #print('j={}, A={}'.format(j, A))
#print('A={}'.format(A))
point = 0
for i in range(N):
    if T[i] == 'r' and A[i] == 'p':
        d = P
    elif T[i] == 's' and A[i] == 'r':
        d = R
    elif T[i] == 'p' and A[i] == 's':
        d = S
    else:
        d = 0
    point = point + d
print(point)

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'

if p ==s and r > p:
    rsp[0] = 'r'
    rsp[1] = 's'
    rsp[2] = 'p'
if r ==s and p > r:
    rsp[0] = 'p'
    rsp[1] = 's'
    rsp[2] = 'r'
if r ==p and p > s:
    rsp[0] = 'p'
    rsp[1] = 'r'
    rsp[2] = 's'
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()
RA,SA,PA=0,0,0
for i in range(0,N-K):
  if T[i]!=T[i+K]:
    if T[i]=='r':
      RA+=1
    if T[i]=='s':
      SA+=1
    if T[i]=='p':
      PA+=1
for i in range(N-K,N):
  if T[i]=='r':
    RA+=1
  if T[i]=='s':
    SA+=1
  if T[i]=='p':
    PA+=1         
ans=RA*P+SA*R+PA*S
print(ans)

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

dic = {'r':p, 's':r, 'p':s}
flg = 0
score = 0
for i in range(k):
    for j in range(i, n-k, k):
        if t[j]==t[j+k] and flg==0:
            score -= dic[t[j]]
            flg = 2
        flg = max(0, flg-1)

for i, j in dic.items():
    score += t.count(i)*j
print(score)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = str(input())
score = 0
prev = ""
for i in range(0,K):
    for j in range(i,N,K):
        if prev != T[j:j+1]:
            if T[j:j+1] == "r":
                score += P
            elif T[j:j+1] == "s":
                score += R
            else:
                score += S
            prev = T[j:j+1]
        else:
            prev = ""
print(score)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 0
cnt = 0
for i in range(N):

    hand = T[i]
    if i >= K:
        before_hand = T[i-K]

        if hand is not before_hand:
            if hand == 's':
                ans += R
            elif hand == 'p':
                ans += S
            else:
                ans += P
        elif hand is before_hand:
            cnt = i
            if i > cnt+K:
                if hand == 's':
                    ans += R
                elif hand == 'p':
                    ans += S
                else:
                    ans += P
                cnt = i
 
    else:
        if hand == 's':
            ans += R
        elif hand == 'p':
            ans += S
        else:
            ans += P
        if hand is T[i+1]:
                cnt = i+1


print(ans)

Submission status: Wrong Answer

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

from collections import Counter
winners_nums = sorted([R, S, P])
winners = Counter({R:'r', S: 's', P: 'p'})

min_winner = winners.get(winners_nums[0])
second_min = winners.get(winners_nums[1])
top = winners.get(winners_nums[2])
mapping = {'r': 'p', 's': 'r', 'p': 's'}

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