#P13726. [GCPC 2024] Kitten of Chaos

[GCPC 2024] Kitten of Chaos

题目描述

Karen has a beautiful precious glass object on the shelf in her living room. Unfortunately, her cat Klaus does not like it when there is stuff on his favourite shelf. Everything that is not bolted or glued in place, he will gradually push over the edge while looking Karen straight in the eyes.

:::align{center}

Klaus, 10 seconds before an event that was luckily covered by Karen's insurance.

:::

Now, Klaus' paw slowly executes his diabolical deed. His cute fluffy face radiates inadvertent innocence. Knowing that any intervention would only delay the inevitable, Karen wonders what will happen to the string her sister Kim wrote on the precious glass object. After all, it took Kim a whole week to gather all the bdpq\texttt{bdpq} letters that make up the string.

Can you describe to Karen what the string will look like from her point of view while it tumbles towards destruction?

While falling off the shelf, Karen's precious glass object is subject to the following transformations, described as seen when looking at the object from the front.

  • h\texttt{h}: horizontal flip, e.g. bbq\texttt{bbq} becomes pdd\texttt{pdd}
  • v\texttt{v}: vertical flip, e.g. bbq\texttt{bbq} becomes ppd\texttt{ppd}
  • r\texttt{r}: 180-degree rotation, e.g. bbq\texttt{bbq} becomes bqq\texttt{bqq}

No flips along or rotations about any other axes are possible.

输入格式

The input consists of:

  • One line with a string ss consisting of the letters bdpq\texttt{bdpq} (1s51051 \le |s| \le 5\cdot 10^5), the string printed on the glass object as seen at the start of the fall.
  • One line with a string tt consisting of the letters hvr\texttt{hvr} (1t51051 \le |t| \le 5\cdot 10^5) giving the sequence of transformations in the order that they occur during the fall.

输出格式

Output the string that can be seen at the moment the glass object touches the ground and just before it shatters into pieces.

bbq
h
pdd
bbq
v
ppd
bbq
r
bqq
ppbddbq
hvrhv
bqppqdd