AtCoder Beginner Contest 469
G
K-nacci 操作
K-nacci Operations
AtCoder
⌀ 2804
原题
← F→

K-nacci 操作AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given $K$ strings $S_1, S_2, \ldots, S_K$ consisting of a and b. Also, for an integer $i > K$, define the string $S_i$ as the concatenation of $S_{i-1}, S_{i-2}, \ldots, S_{i-K}$ in this order.

给定 $K$ 个仅由 a 和 b 组成的字符串 $S_1, S_2, \ldots, S_K$。此外,对于整数 $i > K$,定义字符串 $S_i$ 为按顺序连接 $S_{i-1}, S_{i-2}, \ldots, S_{i-K}$ 得到的字符串。AI (CI翻译)

You perform the following operation on a string $T$.

对字符串 $T$ 执行以下操作。AI (CI翻译)

  • Perform the following operations for $j = 1, 2, \ldots, |S_N|$ in order, where $|S_N|$ is the length of $S_N$.
  • If the $j$-th character of $S_N$ is a, move the first character of $T$ to the end.
    • If the $j$-th character of $S_N$ is b, reverse $T$ entirely. That is, reverse the order of the characters of $T$.
  • 按顺序对 $j = 1, 2, \ldots, |S_N|$ 执行以下操作,其中 $|S_N|$ 表示 $S_N$ 的长度。
  • 如果 $S_N$ 的第 $j$ 个字符是 a,则将 $T$ 的第一个字符移到末尾。
    • 如果 $S_N$ 的第 $j$ 个字符是 b,则将整个 $T$ 反转,也就是将字符顺序倒置。
AI (CI翻译)

Find the string $T$ after the series of operations.

求执行完这一系列操作后的字符串 $T$。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $2 \leq K \leq 100$
  • $K$ is an integer.
  • $S_i$ is a non-empty string consisting of a and b. $(1 \leq i \leq K)$
  • The sum of the lengths of $S_1, S_2, \ldots, S_K$ is at most $2 \times 10^5$.
  • $1 \leq N \leq 10^{18}$
  • $N$ is an integer.
  • $T$ is a string consisting of lowercase English letters with length between $1$ and $2 \times 10^5$, inclusive.
  • $2 \leq K \leq 100$
  • $K$ 是整数。
  • $S_i$ 是一个非空且仅由 a 和 b 组成的字符串。$(1 \leq i \leq K)$
  • $S_1, S_2, \ldots, S_K$ 的长度之和不超过 $2 \times 10^5$。
  • $1 \leq N \leq 10^{18}$
  • $N$ 是整数。
  • $T$ 是一个由小写英文字母组成的字符串,长度在 $1$ 到 $2 \times 10^5$ 之间(含端点)。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

K
S_1
S_2
\vdots
S_K
N
T

K
S_1
S_2
\vdots
S_K
N
T
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the answer.

输出答案。AI (CI翻译)

样例

Input #1
3
a
aa
b
5
abc
Output #1
cab
$S_1 =$ `a`, $S_2 =$ `aa`, $S_3 =$ `b`, $S_4 =$ `baaa`, and $S_5 =$ `baaabaa`. Through the operations, the string $T$ changes as `abc` → `cba` → `bac` → `acb` → `cba` → `abc` → `bca` → `cab`, so the string $T$ after the series of operations is `cab`.
Input #2
2
a
ba
6
fibonacci
Output #2
canobific
Input #3
5
aba
a
bb
ba
aab
1000000000000000000
abcba
Output #3
aabcb
题目信息
题号
abc469_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。