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 t of length m, consisting of lowercase English letters, and he would like to split it into parts. He calls a pair of strings (x,y) beautiful if and only if there exists a sequence of strings a1,a2,…,ak, such that:
- t=a1+a2+…+ak, where + denotes string concatenation.
- For each 1≤i≤k, at least one of the following holds: ai=x, or ai=y.
Cocoly has another string s of length n, consisting of lowercase English letters. Now, for each 1≤i<n, Cocoly wants you to determine whether the pair of strings (s1s2…si,si+1si+2…sn) 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 有一个长度为 m 的字符串 t,仅由小写英文字母组成,他希望将其分割为若干段。我们称一对字符串 (x,y) 是优美的,当且仅当存在一个字符串序列 a1,a2,…,ak,满足:
- t=a1+a2+…+ak,其中 + 表示字符串连接;
- 对每个 1≤i≤k,以下条件至少有一个成立:ai=x 或 ai=y。
Cocoly 还有另一个长度为 n 的字符串 s,也仅由小写英文字母组成。现在,对每个 1≤i<n,你需要判断字符串对 (s1s2…si,si+1si+2…sn) 是否是优美的。
注意:由于输入与输出规模较大,你可能需要对此题进行输入/输出优化。
例如,在 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 T (1≤T≤105) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n and m (2≤n≤m≤5⋅106) — the lengths of s and the length of t.
The second line of each test case contains a single string s of length n, consisting only of lowercase English letters.
The third line of each test case contains a single string t of length m, consisting only of lowercase English letters.
It is guaranteed that the sum of m over all test cases does not exceed 107.
每个测试包含多个测试用例。第一行包含一个整数 T(1≤T≤105),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(2≤n≤m≤5⋅106),分别表示字符串 s 和字符串 t 的长度。
每个测试用例的第二行包含一个长度为 n 的字符串 s,仅由小写英文字母组成。
每个测试用例的第三行包含一个长度为 m 的字符串 t,仅由小写英文字母组成。
保证所有测试用例中 m 的总和不超过 107。
输出格式
For each test case, output a single binary string r of length n−1: for each 1≤i<n, if the i-th pair is beautiful, ri=1; otherwise, ri=0. Do not output spaces.
对于每个测试用例,输出一个长度为 n−1 的二进制字符串 r:对每个 1≤i<n,若第 i 个数对是优美的,则 ri=1;否则 ri=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=aba, t=ababa.
- For i=1: Cocoly can split t=a+ba+ba, so the string pair (a,ba) is beautiful.
- For i=2: Cocoly can split t=ab+ab+a, so the string pair (ab,a) is beautiful.
In the second test case, s=czzz, t=czzzzzczzz.
- For i=1: It can be proven that there is no solution to give a partition of t using strings c and zzz.
- For i=2: Cocoly can split t into cz+zz+zz+cz+zz.
- For i=3: Cocoly can split t into czz+z+z+z+czz+z.
在第一个测试用例中,s=aba,t=ababa。
- 对于 i=1:Cocoly 可以将 t 拆分为 a+ba+ba,因此字符串对 (a,ba) 是优美的。
- 对于 i=2:Cocoly 可以将 t 拆分为 ab+ab+a,因此字符串对 (ab,a) 是优美的。
在第二个测试用例中,s=czzz,t=czzzzzczzz。
- 对于 i=1:可以证明,不存在使用字符串 c 和 zzz 对 t 进行划分的方案。
- 对于 i=2:Cocoly 可以将 t 拆分为 cz+zz+zz+cz+zz。
- 对于 i=3:Cocoly 可以将 t 拆分为 czz+z+z+z+czz+z。
输入解题思路,AI测评打分。不知道怎么写?