atcoder#EXAWIZARDS2019C. Snuke the Wizard
Snuke the Wizard
Score : points
Problem Statement
There are squares numbered to from left to right. Each square has a character written on it, and Square has a letter . Besides, there is initially one golem on each square.
Snuke cast spells to move the golems.
The -th spell consisted of two characters and , where is L
or R
.
When Snuke cast this spell, for each square with the character , all golems on that square moved to the square adjacent to the left if is L
, and moved to the square adjacent to the right if is R
.
However, when a golem tried to move left from Square or move right from Square , it disappeared.
Find the number of golems remaining after Snuke cast the spells.
Constraints
- and are uppercase English letters.
- is
L
orR
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 4
ABC
A L
B L
B R
A R
2
- Initially, there is one golem on each square.
- In the first spell, the golem on Square tries to move left and disappears.
- In the second spell, the golem on Square moves left.
- In the third spell, no golem moves.
- In the fourth spell, the golem on Square moves right.
- After the four spells are cast, there is one golem on Square and one golem on Square , for a total of two golems remaining.
8 3
AABCBDBA
A L
B R
A R
5
- After the three spells are cast, there is one golem on Square , two golems on Square and two golems on Square , for a total of five golems remaining.
- Note that a single spell may move multiple golems.
10 15
SNCZWRCEWB
B R
R R
E R
W R
Z L
S R
Q L
W L
B R
C L
A L
N L
E R
Z L
S L
3