Problem Statement
(略)
题目来源
Output
Print the maximum total score earned in the game.
Sample Input 1
5 2
8 7 6
rsrpr
Sample Output 1
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
比赛时一直挂,根本不知道错在哪里,赛后看了别人写的,感觉也没啥差别,不过我看到有写得很简便的方法,就在这边记录一下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n,k,r,s,p;
string T;
int ans=0,vis[100005];
memset(vis,0,sizeof(vis));
cin>>n>>k>>r>>s>>p>>T;
for(int i=0;i<n;i++){
if(i-k>=0 && vis[i-k] && T[i]==T[i-k]) continue;
if(T[i]=='r') ans+=p;
if(T[i]=='s') ans+=r;
if(T[i]=='p') ans+=s;
vis[i]=1;
}
cout<<ans;
return 0;
}