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 A():
    temp = input().split()
    print(''.join(temp[::-1]))

def B():
    temp = [int(n) for n in input().split()]
    A = temp[0]
    B = temp[1]
    K = temp[2]
    to_minus = min(A, K)
    A -= to_minus
    K -= to_minus
    if K > 0:
        B -= min(B, K)
    print (A, B)

import math
def C():
    X = int(input())
    if X <= 2:
        print(2)
        return

    def isPrime(n):
        if n <= 3:
            return True
        if(n % 2 == 0 or n % 3 == 0): 
            return False
      
        for i in range(5,int(math.sqrt(n) + 1), 6):  
            if(n%i == 0 or n%(i + 2) == 0): 
                return False
        
        return True
    
    while True:
        if isPrime(X):
            print(X)
            return
        X += 1

def D():
    temp = [int(n) for n in input().split()]
    N = temp[0]
    K = temp[1]

    temp = [int(n) for n in input().split()]
    point_dict = {'r': temp[0], 's': temp[1], 'p': temp[2]}

    T = input()

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

    ans = 0
    last_choice = ['' for i in range(K)]
    for i, c in enumerate(T):
        if i<K or last_choice[i%K] != winning_rule[c]:
            last_choice[i%K] = winning_rule[c]
            ans += point_dict[winning_rule[c]]
        else:
            last_choice[i%K] = c
    print(ans)
    
D()

Submission status: Wrong Answer

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

h = [''] * n
c = {'r': 'p', 's': 'r', 'p': 's'}
points = 0

for i, ti in enumerate(t):
    ci = c[ti]
    if i < k or h[i - k] != c[ti]:
        h[i] = ci
        points += eval(ci)
    else:
        p1, p2 = eval(ci), eval(h[i - k])
        if p1 > p2:
            h[i] = ci
            if t[i - k] == c[t[i - k]]:
                points -= p2
            points += p1
        else:
            h[i] = ti


print(points)

Submission status: Wrong Answer

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

h = [''] * n
c = {'r': 'p', 's': 'r', 'p': 's'}
points = 0

for i, ti in enumerate(t):
    ci = c[ti]
    if i < k or h[i - k] != c[ti]:
        h[i] = ci
        points += eval(ci)
    else:
        p1, p2 = eval(ci), eval(h[i - k])
        if p1 > p2:
            h[i] = ci
            points -= p2
            points += p1
        else:
            h[i] = ti


print(points)

Submission status: Wrong Answer

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

h = [''] * n
c = {'r': 'p', 's': 'r', 'p': 's'}
points = 0

for i, ti in enumerate(t):
    ci = c[ti] if i < k or h[i - k] != c[ti] else ti
    h[i] = ci
    if ci != ti:
        points += eval(ci)

print(points)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
# Kを無視した勝ち手のリスト
kachite = []
for i in range(N):
  if T[i] == 'r':
    kachite.append(P)
  elif T[i] == 's':
    kachite.append(R)
  else:
    kachite.append(S)

# 勝ち手リストを頭から見ていき、jとj-Kの勝ち手が同じ場合は変更する
for j in range(N):
  if j-K>=0:
    # if kachite[j]==kachite[j-K] and kachite[j-K]!=0:
    if kachite[j]==kachite[j-K]:
      #K回前の勝ち手が同じ(得点が同じ)、かつ、0点ではない場合
      kachite[j] = 0 # K回前、K回後のいずれでもない手を出したことにする
# 最終得点を出力
print(sum(kachite))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
if  n%k!=0:
    leng=n//k+1
else:
    leng=n//k
data=[[0 for i in range(leng)] for j in range(n//(n//k))]
ans=0
for i in range(0,n//(n//k)):
    for j in range(0,leng):
        if i+(k*j)>=n:
            break
        data[i][j]=t[i+(k*j)]
rz=0
sz=1
pz=2
for j in range(0,n//(n//k)):
    dp=[[0 for x in range(3)] for y in range(leng)]
    if data[j][0]=='r':
        dp[0][rz]=0
        dp[0][sz]=0
        dp[0][pz]=p
    elif data[j][0]=='s':
        dp[0][rz]=r
        dp[0][sz]=0
        dp[0][pz]=0
    elif data[j][0]=='p':
        dp[0][rz]=0
        dp[0][sz]=s
        dp[0][pz]=0

    for i in range(1,leng):
        if data[j][i]=='r':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+p+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='s':
            dp[i][rz]=dp[i][rz]+r+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='p':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+s+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        else:
            dp[i][rz]=dp[i-1][rz]
            dp[i][sz]=dp[i-1][sz]
            dp[i][pz]=dp[i-1][pz]
    ans+=max(dp[-1][rz],dp[-1][sz],dp[-1][pz])
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
if  n%k!=0:
    leng=n//k+1
else:
    leng=n//k
data=[[0 for i in range(leng)] for j in range(n//(n//k))]
ans=0
for i in range(0,n//(n//k)):
    for j in range(0,leng):
        if i+(k*j)>=n:
            break
        data[i][j]=t[i+(k*j)]

rz=0
sz=1
pz=2
for j in range(0,n//(n//k)):
    dp=[[0 for x in range(3)] for y in range(leng)]
    if data[j][0]=='r':
        dp[0][rz]=0
        dp[0][sz]=0
        dp[0][pz]=p
    elif data[j][0]=='s':
        dp[0][rz]=r
        dp[0][sz]=0
        dp[0][pz]=0
    else :
        dp[0][rz]=0
        dp[0][sz]=s
        dp[0][pz]=0

    for i in range(1,leng):
        if data[j][i]=='r':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+p+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='s':
            dp[i][rz]=dp[i][rz]+r+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        else :
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+s+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
    ans+=max(dp[-1][rz],dp[-1][sz],dp[-1][pz])
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
data=[[0 for i in range(n//k)] for j in range(n//(n//k))]
ans=0
for i in range(0,n//(n//k)):
    for j in range(0,n//k):
        data[i][j]=t[i+(k*j)]

rz=0
sz=1
pz=2
for j in range(0,n//(n//k)):
    dp=[[0 for x in range(3)] for y in range(n//k)]
    if data[j][0]=='r':
        dp[0][rz]=0
        dp[0][sz]=0
        dp[0][pz]=p
    elif data[j][0]=='s':
        dp[0][rz]=r
        dp[0][sz]=0
        dp[0][pz]=0
    else :
        dp[0][rz]=0
        dp[0][sz]=s
        dp[0][pz]=0

    for i in range(1,n//k):
        if data[j][i]=='r':
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+p+max(dp[i-1][sz],dp[i-1][rz])
        elif data[j][i]=='s':
            dp[i][rz]=dp[i][rz]+r+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
        else :
            dp[i][rz]=dp[i][rz]+max(dp[i-1][sz],dp[i-1][pz])
            dp[i][sz]=dp[i][sz]+s+max(dp[i-1][rz],dp[i-1][pz])
            dp[i][pz]=dp[i][pz]+max(dp[i-1][sz],dp[i-1][rz])
    ans+=max(dp[-1][rz],dp[-1][sz],dp[-1][pz])
print(ans)

Submission status: Wrong Answer

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


def pon(computer, mine):
    if computer == 'r' and mine == 2: return P
    if computer == 's' and mine == 0: return R
    if computer == 'p' and mine == 1: return S
    return 0


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

ans = 0
for st in range(K):
    for i in range(st, N, K):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][k] = max(dp[i+1][k], dp[i+1-K][j] + pon(T[i], k))
    ans += max(dp[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().strip()


def pon(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+10)]

ans = 0
for st in range(K):
    for i in range(st, N, K):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][k] = max(dp[i+1][k], dp[i+1-K][j] + pon(i, k))
    ans += max(dp[i+1])

print(ans)

Submission status: Wrong Answer

Solution code:
H = list(map(int, input().split()))
A = list(map(int, input().split()))
T = input()
P=A[2]
R=A[0]
S=A[1]
k=H[1]
ans = 0
T = list(T)

for i in range(int(H[0])):
    a=i-k
    b=T[0]
    if(a<0):
        if(T[i]=="r"):
                ans+=P
                print("p")
        if(T[i]=="s"):
                ans+=R
                print("r")
        if(T[i]=="p"):
                ans+=S
                print("s")
    else:
        if(T[i]=="r"):
            if(T[a] !="r"):
                ans+=P
                print("p")
            else:
                T[i]="l"
                print("n")

        if(T[i]=="s"):
            if(T[a] !="s"):
                ans+=R
                print("r")
            else:
                T[i]="l"
                print("n")
        if(T[i]=="p"):
            if(T[a] !="p"):
                ans+=S
                print("s")
            else:
                T[i]="l"
                print("n")
print(ans)

Submission status: Wrong Answer

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

st = ''
for i in t:
    if i == 'r':
        st += 'p'
    elif i == 'p':
        st += 's'
    else:
        st += 'r'

stt = st[:k]

for i in range(k, n):
    if st[i] != stt[i - k]:
        stt += st[i]
    else:
        stt += 'x'

sum = 0
for i in stt:
    if i == 'r':
        sum += r
    elif i == 's':
        sum += s
    elif i == 'p':
        sum += p
    else:
        pass

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = list(map(int, input().split())) #グー・チョキ・パー
W=str(input())#rはグー・sはチョキ・pはパー
V=list()
Q=list()

#重複考慮しない勝ちパターン
def all_win(A):
    for i in range(len(A)):
        if A[i]=='r':
            V.append('p')
        elif A[i]=='s':
            V.append('r')
        elif A[i]=='p':
            V.append('s')
    return(V)
#重複考慮した勝ちパターン：
def win_no_duplicate(C):
    for i in range(0,len(C)):
        if i < K:
            C[i]=C[i]
        else:
            if C[i]==C[i-K]:
                if C[i]=='p':
                    C[i]='r'
                elif C[i]=='s':
                    C[i]='p'
                elif C[i]=='r':
                    C[i]='s'
            else:
                C[i]=C[i]
    
    return(C)
#得点計算
def total_score(D):
    E=list()
    for i in range(len(D)):
        #機械のパターンと比較し、あいこの場合を覗く
        if D[i]==W[i]:
            E.append(0)
        #買った時の得点
        else:
            if D[i]=='r':
                E.append(8)
            elif D[i]=='s':
                E.append(7)
            elif D[i]=='p':
                E.append(6)
    return(sum(E))

F=all_win(W)
G=win_no_duplicate(F)
SUM=total_score(G)
print(SUM)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

for i in range(N,K):
    if T[k+j]==T[j]:
        T[k+j]="x"
    #絶対に次の手を邪魔しない選択ができるので,ダブったら後の手を×にしときゃ良い
ans=T.count("r")*P+T.count("s")*R+T.count("p")*S

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
rsp = ['r','s','p']
dp = [0 for i in range(N)]
def point(i,dp,T):
    if dp[i] == "r" and T[i] == "s":
        return R
    elif dp[i] == "s" and T[i] == "p":
        return S
    elif dp[i] == "p" and T[i] == "r":
        return P
    else:
        return 0
def win(i,dp,T):
    if T[i] == "s":
        return "r"
    elif T[i] == "p":
        return "s"
    elif T[i] == "r":
        return "p"
    

sumpoint = 0
for i in range(K):
    dp[i] = win(i,dp,T)
    sumpoint += point(i,dp,T)
for i in range(K,N-1):
    rsp = ['r','s','p']
    dp[i] = win(i,dp,T)
    if dp[i] == dp[i-K]:
        rsp.remove(win(i,dp,T))
        if K == 1 and rsp.count(win(i+1,dp,T)) == 1:
            rsp.remove(win(i+1,dp,T))
        dp[i] = rsp[0]
    else:
        dp[i] = win(i,dp,T)
        sumpoint += point(i,dp,T)
if dp[N-1] != dp[N-1-K]:
    dp[N-1] = win(N-1,dp,T)
    sumpoint = sumpoint +  point(N-1,dp,T)
print(sumpoint)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
R,S,P = map(int,input().split())
gan = ["r","s","p"]
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-2*k):
    gan = ["r","s","p"]
    if W[i] == W[i+k] and W[i+k] == W[i+2*k] :
        W[i+k] = T[i+k]
        if W[i+k] == "r":
            ans -= P
        elif W[i+k] == "s":
            ans -= R
        elif W[i+k] == "p":
            ans -= S
            
    elif W[i] == W[i+k] and W[i+k] != W[i+2*k]:
        gan.remove(W[i])
        gan.remove(W[i+2*k])
        W[i+k] = "".join(gan)
        if W[i+k] == "r":
            ans -= P
        elif W[i+k] == "s":
            ans -= R
        elif W[i+k] == "p":
            ans -= S
        
print(ans)

Submission status: Wrong Answer

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

count = 0
result = []

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


for i in range(N):
  x = T[i]
  hand, point = get(x)
  if i < K:
    # 前回の結果は気にしなくても良いとき
    result.append((hand, point))
  elif hand != result[i-K][0]:
    result.append((hand, point))
  else:
    if i + K >= N:
      # 後のことを考えなくて良いとき
      result.append((hand, 0))
    else:
      next = list(filter(lambda x: x not in (T[i+K], hand), ["r", "s", "p"]))[0]
      result.append((next, 0))

print(sum(list(map(lambda x: x[1], result))))

Submission status: Wrong Answer

Solution code:
n,k = (int(x) for x in input().split())
rp,sp,pp = (int(x) for x in input().split())
t = input()
total_point = 0

for i in range(n):
    if t[i] == "r":
        total_point += pp
    elif t[i] == "s":
        total_point += rp
    else:
        total_point += sp

for i in range(n):
    if i > k:
        if t[i] == t[i - k]:
            if t[i] == "r":
                total_point -= pp
            elif t[i] == "s":
                total_point -= rp
            else:
                total_point -= sp
            
print(total_point)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

score=0
li=[]

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = []
dp = [[0]*4 for _ in range(n+1)]

for i in range(n):
    if i >= k:
        ng = ans[i - k]

        if ng == 'r':
            dp[i + 1][0] = 0
            if t[i] == 'r':
                dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
                dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2]) + p
            elif t[i] == 's':
                dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
                dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
            elif t[i] == 'p':
                dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2]) + s
                dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
        elif ng == 's':
            dp[i + 1][1] = 0
            if t[i] == 'r':
                dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
                dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2]) + p
            elif t[i] == 's':
                dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2]) + r
                dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
            elif t[i] == 'p':
                dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
                dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
        elif ng == 'p':
            dp[i + 1][2] = 0
            if t[i] == 'r':
                dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
                dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
            elif t[i] == 's':
                dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2]) + r
                dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
            elif t[i] == 'p':
                dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
                dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2]) + s
    else:
        if t[i] == 'r':
            dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
            dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
            dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2]) + p
        elif t[i] == 's':
            dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2]) + r
            dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
            dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
        elif t[i] == 'p':
            dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
            dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2]) + s
            dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])

    rock, sci, paper = dp[i+1][0], dp[i+1][1], dp[i+1][2]
    if rock == max(rock, sci, paper):
        ans += ['r']
    elif sci == max(rock, sci, paper):
        ans += ['s']
    elif paper == max(rock, sci, paper):
        ans += ['p']

# print('dp: ', dp)
# print('ans:', ans)
print(max(dp[n][0], dp[n][1], dp[n][2]))

Submission status: Wrong Answer

Solution code:


kaisu, limit = map(int, input().split())
goo, choki, par = map(int, input().split())
tejyun = list(input())

ans = 0
backlog = []


def getWinning(hand):
    # input r, s, p
    if hand == 'r':
        return 'p'
    elif hand == 's':
        return 'r'
    else:
        return 's'

for idx, te in enumerate(tejyun):
    prevIdx = idx - limit
    nextIdx = idx + limit

    if prevIdx >= 0:
        prevHand = backlog[prevIdx]
        if getWinning(te) == prevHand:
            # 勝てないので次に負けない手をだす
            try:
                nextHand = getWinning(tejyun[nextHand])
                # prevでもnextでもないhandをだす
                if prevHand != 'r' and nextHand != 'r':
                    backlog.append('r')
                elif prevHand != 's' and nextHand != 's':
                    backlog.append('s')
                else:
                    backlog.append('p')
            except:
                # どちらでも良い
                if prevHand != 'r':
                    backlog.append('r')
                elif prevHand != 's':
                    backlog.append('s')
            continue
        
    # 勝てる手を出しスコア獲得
    nowHand = getWinning(te)
    backlog.append(nowHand)
    if nowHand == 'r':
        ans += goo
    elif nowHand == 's':
        ans += choki
    else:
        ans += par

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
bbn=1000000007
	
#+++++
		
def main():
	n, k = map(int, input().split())
	r, s, p =  map(int, input().split())
	t = input()
	dd={'s':r, 'p':s, 'r':p}
	point = lambda c : dd[c]
	
	max_p=sum([point(c) for c in t])
	same_k={'s':0, 'p':0, 'r':0}
	tn=t
	for i in range(k+1,n):
		if tn[i]==tn[i-k] and tn[i]!='_':
			same_k[tn[i]] += 1
			same_k[i] = '_'
	down=0
	for cc in ['r','s','p']:
		down+=same_k[cc]*point(cc)
			
	print(max_p-down)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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]:
        if i + K < N:
            hands[i] = list(set('rps') - set(T[i + K]) - set(T[i]))[0]
        else:
            hands[i] = T[i]
    else:
        hands[i] = d1[T[i]]
        result += d2[T[i]]
print(result)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
score_map = {
    "r": p,
    "p": s,
    "s": r,
}
score = [0] * n
for i, c in enumerate(t):
    score[i] = score_map[c]
ans = 0
for i in range(k):
    skipped_list = score[i::k]
    for j, c in enumerate(skipped_list[1:]):
        if skipped_list[j] == c:
            skipped_list[j+1] = 0
    ans += sum(skipped_list)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
r, s, p = map(int, input().split())
t = input()
scoremap = {
    "r": p,
    "p": s,
    "s": r
}
t_ls = [scoremap[i] for i in t]

def best(ls: list):
    for i in range(len(ls) - 1):
        if ls[i] == ls[i + 1]:
            ls[i + 1] = 0
    num=sum(ls)
    return num

total=0
for i in range(k):
    ls = t_ls[i::k]
    total+=best(ls)
print(total)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
r, s, p = map(int, input().split())
t = input()
scoremap = {
    "r": p,
    "p": s,
    "s": r
}
t_ls = [scoremap[i] for i in t]

def best(ls: list):
    print(ls)
    for i in range(len(ls) - 1):
        if ls[i] == ls[i + 1]:
            ls[i + 1] = 0
    print(ls)
    num=sum(ls)
    return num

total=0
for i in range(k):
    ls = t_ls[i::k]
    total+=best(ls)
print(total)

Submission status: Wrong Answer

Solution code:
from operator import add
from functools import reduce

N, K = list(map(int, input().split()))
rsp = dict(zip("spr", list(map(int, input().split()))))
T = input()

score = [rsp[s] for s in T]
for i in range(N - K):
    s1 = score[i]
    s2 = score[i + K]
    if s1 == s2:
        score[i + K] = 0
print(reduce(add, score))

Submission status: Wrong Answer

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

for i in range(N) :
    if T[i] == 'r' :
        T_new.append(P)
    elif T[i] == 's' :
        T_new.append(R)
    else :
        T_new.append(S)
for i in range(K,N) :
    if (int(T_new[i-K]) == T_new[i]) :
        if T_new[i-K] == T_new[i] :
            T_new[i] = T_new[i] + 0.1
        
buf = 0
for i in range(N) :
    if T_new[i] == int(T_new[i]) :
        buf += T_new[i]

print(buf)

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)
            right = cur+k
            if right < n:
                need_right = dict[a[right]]
                cant[cur].append(need_right)
            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:
from operator import add
from functools import reduce

N, K = list(map(int, input().split()))
rsp = dict(zip("spr", list(map(int, input().split()))))
T = input()

score = [rsp[s] for s in T]
for i in range(N - 1, 0 + K - 1, -1):
    s1 = score[i]
    s2 = score[i - K]
    if s1 == s2:
        score[i - K] = 0
print(reduce(add, score))

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]]:
            if i + K < N:
                l[k].append(T[i+k])
            else:
                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 = 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)