CF2053G.Naive String Splits

NOI/NOI+/CTSC

通过率:0%

时间限制:10.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

And I will: love the world that you've adored; wish the smile that you've longed for. Your hand in mine as we explore, please take me to tomorrow's shore.

— Faye Wong, As Wished

Cocoly has a string tt of length mm, consisting of lowercase English letters, and he would like to split it into parts. He calls a pair of strings (x,y)(x, y) beautiful if and only if there exists a sequence of strings a1,a2,…,aka_1, a_2, \ldots, a_k, such that:

  • t=a1+a2+…+akt = a_1 + a_2 + \ldots + a_k, where ++ denotes string concatenation.
  • For each 1≤i≤k1 \leq i \leq k, at least one of the following holds: ai=xa_i = x, or ai=ya_i = y.

Cocoly has another string ss of length nn, consisting of lowercase English letters. Now, for each 1≤i<n1 \leq i \lt n, Cocoly wants you to determine whether the pair of strings (s1s2…si, si+1si+2…sn)(s_1s_2 \ldots s_i, \, s_{i+1}s_{i+2} \ldots s_n) is beautiful.

Note: since the input and output are large, you may need to optimize them for this problem.

For example, in C++, it is enough to use the following lines at the start of the main() function:

int main() {    std::ios::sync_with_stdio(false);    std::cin.tie(nullptr); std::cout.tie(nullptr);}

我愿:爱你所爱的世界,许你所盼的微笑。携手共赴未知之旅,请带我抵达明日之岸。

——王菲《如愿》(视频链接)

Cocoly 有一个长度为 mm 的字符串 tt,仅由小写英文字母组成,他希望将其分割为若干段。我们称一对字符串 (x,y)(x, y) 是优美的,当且仅当存在一个字符串序列 a1,a2,…,aka_1, a_2, \ldots, a_k,满足:

  • t=a1+a2+…+akt = a_1 + a_2 + \ldots + a_k,其中 ++ 表示字符串连接;
  • 对每个 1≤i≤k1 \leq i \leq k,以下条件至少有一个成立:ai=xa_i = x 或 ai=ya_i = y。

Cocoly 还有另一个长度为 nn 的字符串 ss,也仅由小写英文字母组成。现在,对每个 1≤i<n1 \leq i < n,你需要判断字符串对 (s1s2…si, si+1si+2…sn)(s_1s_2 \ldots s_i,\, s_{i+1}s_{i+2} \ldots s_n) 是否是优美的。

注意:由于输入与输出规模较大,你可能需要对此题进行输入/输出优化。

例如,在 C++ 中,只需在 main() 函数开头加入如下几行代码即可:

int main() {    std::ios::sync_with_stdio(false);    std::cin.tie(nullptr); std::cout.tie(nullptr);}

输入格式

Each test contains multiple test cases. The first line contains an integer TT (1≤T≤1051 \leq T \leq 10^5) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and mm (2≤n≤m≤5⋅1062 \leq n \leq m \leq 5 \cdot 10^6) — the lengths of ss and the length of tt.

The second line of each test case contains a single string ss of length nn, consisting only of lowercase English letters.

The third line of each test case contains a single string tt of length mm, consisting only of lowercase English letters.

It is guaranteed that the sum of mm over all test cases does not exceed 10710^7.

每个测试包含多个测试用例。第一行包含一个整数 TT(1≤T≤1051 \leq T \leq 10^5),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤m≤5⋅1062 \leq n \leq m \leq 5 \cdot 10^6),分别表示字符串 ss 和字符串 tt 的长度。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,仅由小写英文字母组成。

每个测试用例的第三行包含一个长度为 mm 的字符串 tt,仅由小写英文字母组成。

保证所有测试用例中 mm 的总和不超过 10710^7。

输出格式

For each test case, output a single binary string rr of length n−1n - 1: for each 1≤i<n1 \leq i \lt n, if the ii-th pair is beautiful, ri=1r_i=\texttt{1}; otherwise, ri=0r_i=\texttt{0}. Do not output spaces.

对于每个测试用例,输出一个长度为 n−1n - 1 的二进制字符串 rr:对每个 1≤i<n1 \leq i \lt n,若第 ii 个数对是优美的,则 ri=1r_i=\texttt{1};否则 ri=0r_i=\texttt{0}。不要输出空格。

输入输出样例

  • 输入#1

    7
    3 5
    aba
    ababa
    4 10
    czzz
    czzzzzczzz
    5 14
    dream
    dredreamamamam
    5 18
    tcccc
    tcctccccctccctcccc
    7 11
    abababc
    abababababc
    7 26
    aaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaa
    19 29
    bbbbbbbbbbbbbbbbbbb
    bbbbbbbbbbbbbbbbbbbbbbbbbbbbb

    输出#1

    11
    011
    0010
    0000
    010100
    111111
    110010001100010011

说明/提示

In the first test case, s=abas = \tt aba, t=ababat = \tt ababa.

  • For i=1i = 1: Cocoly can split t=a+ba+bat = \texttt{a} + \texttt{ba} + \texttt{ba}, so the string pair (a,ba)(\texttt{a}, \texttt{ba}) is beautiful.
  • For i=2i = 2: Cocoly can split t=ab+ab+at = \texttt{ab} + \texttt{ab} + \texttt{a}, so the string pair (ab,a)(\texttt{ab}, \texttt{a}) is beautiful.

In the second test case, s=czzzs = \tt czzz, t=czzzzzczzzt = \tt czzzzzczzz.

  • For i=1i = 1: It can be proven that there is no solution to give a partition of tt using strings c\texttt{c} and zzz\texttt{zzz}.
  • For i=2i = 2: Cocoly can split tt into cz+zz+zz+cz+zz\texttt{cz} + \texttt{zz} + \texttt{zz} + \texttt{cz} + \texttt{zz}.
  • For i=3i = 3: Cocoly can split tt into czz+z+z+z+czz+z\texttt{czz} + \texttt{z} + \texttt{z} + \texttt{z} + \texttt{czz} + \texttt{z}.

在第一个测试用例中,s=abas = \tt aba,t=ababat = \tt ababa。

  • 对于 i=1i = 1:Cocoly 可以将 tt 拆分为 a+ba+ba\texttt{a} + \texttt{ba} + \texttt{ba},因此字符串对 (a,ba)(\texttt{a}, \texttt{ba}) 是优美的。
  • 对于 i=2i = 2:Cocoly 可以将 tt 拆分为 ab+ab+a\texttt{ab} + \texttt{ab} + \texttt{a},因此字符串对 (ab,a)(\texttt{ab}, \texttt{a}) 是优美的。

在第二个测试用例中,s=czzzs = \tt czzz,t=czzzzzczzzt = \tt czzzzzczzz。

  • 对于 i=1i = 1:可以证明,不存在使用字符串 c\texttt{c} 和 zzz\texttt{zzz} 对 tt 进行划分的方案。
  • 对于 i=2i = 2:Cocoly 可以将 tt 拆分为 cz+zz+zz+cz+zz\texttt{cz} + \texttt{zz} + \texttt{zz} + \texttt{cz} + \texttt{zz}。
  • 对于 i=3i = 3:Cocoly 可以将 tt 拆分为 czz+z+z+z+czz+z\texttt{czz} + \texttt{z} + \texttt{z} + \texttt{z} + \texttt{czz} + \texttt{z}。

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

首页