AT_abc469_g.K-nacci Operations

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given KK strings S1,S2,…,SKS_1, S_2, \ldots, S_K consisting of a and b. Also, for an integer i>Ki > K, define the string SiS_i as the concatenation of Si−1,Si−2,…,Si−KS_{i-1}, S_{i-2}, \ldots, S_{i-K} in this order.

You perform the following operation on a string TT.

  • Perform the following operations for j=1,2,…,∣SN∣j = 1, 2, \ldots, |S_N| in order, where ∣SN∣|S_N| is the length of SNS_N.
    • If the jj-th character of SNS_N is a, move the first character of TT to the end.
    • If the jj-th character of SNS_N is b, reverse TT entirely. That is, reverse the order of the characters of TT.

Find the string TT after the series of operations.

给你 KK 个仅由字符 a 和 b 组成的字符串 S1,S2,…,SKS_1, S_2, \ldots, S_K。此外,对任意大于 KK 的整数 ii,定义字符串 SiS_i 为 Si−1,Si−2,…,Si−KS_{i-1}, S_{i-2}, \ldots, S_{i-K} 按此顺序拼接而成。

你将对字符串 TT 执行如下操作:

  • 对 j=1,2,…,∣SN∣j = 1, 2, \ldots, |S_N|(按此顺序),其中 ∣SN∣|S_N| 表示字符串 SNS_N 的长度,执行以下操作:
    • 若 SNS_N 的第 jj 个字符为 a,则将 TT 的第一个字符移至末尾;
    • 若 SNS_N 的第 jj 个字符为 b,则将整个 TT 反转(即反转 TT 中所有字符的顺序)。

求执行完全部操作后所得的字符串 TT。

输入格式

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

KK
S1S_1
S2S_2
⋮\vdots
SKS_K
NN
TT

输入从标准输入给出,格式如下:

KK
S1S_1
S2S_2
⋮\vdots
SKS_K
NN
TT

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    3
    a
    aa
    b
    5
    abc

    输出#1

    cab
  • 输入#2

    2
    a
    ba
    6
    fibonacci

    输出#2

    canobific
  • 输入#3

    5
    aba
    a
    bb
    ba
    aab
    1000000000000000000
    abcba

    输出#3

    aabcb

说明/提示

Sample 1 Explanation:
S1=S_1 = a, S2=S_2 = aa, S3=S_3 = b, S4=S_4 = baaa, and S5=S_5 = baaabaa.

Through the operations, the string TT changes as abc → cba → bac → acb → cba → abc → bca → cab, so the string TT after the series of operations is cab.

Constraints

  • 2≤K≤1002 \leq K \leq 100
  • KK is an integer.
  • SiS_i is a non-empty string consisting of a and b. (1≤i≤K)(1 \leq i \leq K)
  • The sum of the lengths of S1,S2,…,SKS_1, S_2, \ldots, S_K is at most 2×1052 \times 10^5.
  • 1≤N≤10181 \leq N \leq 10^{18}
  • NN is an integer.
  • TT is a string consisting of lowercase English letters with length between 11 and 2×1052 \times 10^5, inclusive.

样例 1 解释:
S1=S_1 = a,S2=S_2 = aa,S3=S_3 = b,S4=S_4 = baaa,且 S5=S_5 = baaabaa。

通过一系列操作,字符串 TT 的变化过程为 abc → cba → bac → acb → cba → abc → bca → cab,因此经过全部操作后,字符串 TT 为 cab。

限制条件

  • 2≤K≤1002 \leq K \leq 100
  • KK 是一个整数。
  • SiS_i 是由字符 a 和 b 组成的非空字符串。(1≤i≤K)(1 \leq i \leq K)
  • S1,S2,…,SKS_1, S_2, \ldots, S_K 的长度总和不超过 2×1052 \times 10^5。
  • 1≤N≤10181 \leq N \leq 10^{18}
  • NN 是一个整数。
  • TT 是一个由小写英文字母组成的字符串,其长度在 11 到 2×1052 \times 10^5(含)之间。

输入解题思路,AI测评打分。不知道怎么写?

首页