#abc314c. C - Rotate Colored Subsequence
C - Rotate Colored Subsequence
Score : points
问题陈述
给定一个由小写英文字母组成的字符串 ,长度为 。 中的每个字符都涂有一种颜色,共有 种颜色:颜色 、颜色 、...、颜色 ;对于每个 , 的第 个字符涂有颜色 。
按照顺序,对于每个 ,执行以下操作。
- 对涂有颜色 的 的部分执行一次向右的循环移动 位。也就是说,如果从左到右,第 个、第 个、第 个、、第 个字符涂有颜色 ,那么同时将 中的第 个、第 个、第 个、、第 个字符分别替换为 中的第 个、第 个、第 个、、第 个字符。
在上述操作完成后,打印最终的字符串 。
约束条件保证 中至少有一个字符涂有 种颜色中的每种颜色。
以上为kimi 翻译,仅供参考。
Problem Statement
You are given a string of length consisting of lowercase English letters. Each character of is painted in one of the colors: color , color , ..., color ; for each , the -th character of is painted in color .
For each in this order, let us perform the following operation.
- Perform a right circular shift by on the part of painted in color . That is, if the -th, -th, -th, , -th characters are painted in color from left to right, then simultaneously replace the -th, -th, -th, , -th characters of with the -th, -th, -th, , -th characters of , respectively.
Print the final after the above operations.
The constraints guarantee that at least one character of is painted in each of the colors.
Constraints
- , , and are all integers.
- is a string of length consisting of lowercase English letters.
- For each integer , there is an integer such that .
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
8 3
apzbqrcs
1 2 3 1 2 2 1 2
Sample Output 1
cszapqbr
Initially, apzbqrcs
.
- For , perform a right circular shift by on the part of formed by the -st, -th, -th characters, resulting in
cpzaqrbs
. - For , perform a right circular shift by on the part of formed by the -nd, -th, -th, -th characters, resulting in
cszapqbr
. - For , perform a right circular shift by on the part of formed by the -rd character, resulting in
cszapqbr
(here, is not changed).
Thus, you should print cszapqbr
, the final .
Sample Input 2
2 1
aa
1 1
Sample Output 2
aa
update @ 2024/3/10 08:58:01