No.161 Restricted Rock-Paper-Scissors
タグ : / 解いたユーザー数 335
作問者 : 👑
kmjp
Problem Statement
yuki-kun has decided to play restricted rock-paper-scissors with a friend.
In this restricted rock-paper-scissors, a total of N rounds of rock-paper-scissors are played (a draw also counts as one round).
Out of the N rounds, yuki-kun can play rock only G times, scissors only C times, and paper only P times.
yuki-kun earns 3 points for each round he wins and 1 point for each draw. A loss neither increases nor decreases his points.
Fortunately, yuki-kun was able to read all of his friend's moves in advance with his psychic powers.
Find the maximum total points yuki-kun can obtain over the N rounds when he plays optimally.
Input
\(G\) \(C\) \(P\) \(S\)
G, C, P are integers representing the number of times yuki-kun can play rock, scissors, and paper, respectively.
S is a string representing the opponent's moves, consisting only of 'G', 'C', 'P'.
If the i-th character of S is 'G', 'C', or 'P', the opponent's move in the i-th round is rock, scissors, or paper, respectively.
The input satisfies \(1 \le |S| \le 300\) and \(|S| = G + C + P\).
Note that the numbers of rocks, scissors, and papers played by yuki-kun and his friend do not necessarily match.
Output
Output the maximum number of points yuki-kun can obtain, on one line.
Sample
Sample 1
Input
2 1 1 CCGP
Output
12
Playing rock, rock, paper, scissors in this order wins all four rounds.
Sample 2
Input
0 0 5 CCCCC
Output
0
He helplessly loses every round.
Sample 3
Input
7 6 5 GCPGPCPGGGPCCCGPGP
Output
50
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。