#abc303d. D - Shift vs. CapsLock
D - Shift vs. CapsLock
Score : points
问题陈述
您的计算机配备了一个键盘,上面有三个键:'a' 键、Shift 键和 Caps Lock 键。Caps Lock 键上有一个指示灯。最初,Caps Lock 键上的指示灯是关闭状态,屏幕上显示一个空字符串。
您可以按照任意顺序重复进行以下三个操作任意多次:
- 花费 毫秒仅按下 'a' 键。如果 Caps Lock 键的指示灯处于关闭状态,则在屏幕显示的字符串末尾添加
a
;如果指示灯亮着,则添加A
。 - 花费 毫秒同时按下 'a' 键和 Shift 键。如果 Caps Lock 键的指示灯处于关闭状态,则在屏幕显示的字符串末尾添加
A
;如果指示灯亮着,则添加a
。 - 花费 毫秒按下 Caps Lock 键。如果 Caps Lock 键的指示灯处于关闭状态,则将其打开;如果指示灯亮着,则将其关闭。
给定一个由 A
和 a
组成的字符串 ,确定至少需要花费多少毫秒才能使屏幕上显示的字符串等于 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Your computer has a keyboard with three keys: 'a' key, Shift key, and Caps Lock key. The Caps Lock key has a light on it. Initially, the light on the Caps Lock key is off, and the screen shows an empty string.
You can do the following three actions any number of times in any order:
- Spend milliseconds to press only the 'a' key. If the light on the Caps Lock key is off,
a
is appended to the string on the screen; if it is on,A
is. - Spend milliseconds to press the 'a' key and Shift key simultaneously. If the light on the Caps Lock key is off,
A
is appended to the string on the screen; if it is on,a
is. - Spend milliseconds to press the Caps Lock key. If the light on the Caps Lock key is off, it turns on; if it is on, it turns off.
Given a string consisting of A
and a
, determine at least how many milliseconds you need to spend to make the string shown on the screen equal to .
Constraints
- , , and are integers.
- is a string consisting of
A
anda
.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
1 3 3
AAaA
Sample Output 1
9
The following sequence of actions makes the string on the screen equal to AAaA
in milliseconds, which is the shortest possible.
- Spend milliseconds to press the CapsLock key. The light on the Caps Lock key turns on.
- Spend milliseconds to press the 'a' key.
A
is appended to the string on the screen. - Spend milliseconds to press the 'a' key.
A
is appended to the string on the screen. - Spend milliseconds to press the Shift key and 'a' key simultaneously.
a
is appended to the string on the screen. - Spend milliseconds to press the 'a' key.
A
is appended to the string on the screen.
Sample Input 2
1 1 100
aAaAaA
Sample Output 2
6
Sample Input 3
1 2 4
aaAaAaaAAAAaAaaAaAAaaaAAAAA
Sample Output 3
40
update @ 2024/3/10 08:31:43