309589: CF1703D. Double Strings

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:13 Solved:0

Description

Double Strings

题意翻译

给出 $n$ 个字符串 $s_1,s_2\cdots s_n$ 每个字符串最多长 $8$,问对于每个 $s_i(1 \le i \le n)$ ,是否存在两个字符串 $s_j,s_k(1 \le j,k \le n)$($j$ 可能等于 $k$)使得 $s_i=s_j+s_k$ ,即 $s_i$ 可以由 $s_j,s_k$ 拼接得到。若存在,输出 $1$,否则输出 $0$。共 $t$ 组数据。

题目描述

You are given $ n $ strings $ s_1, s_2, \dots, s_n $ of length at most $ \mathbf{8} $ . For each string $ s_i $ , determine if there exist two strings $ s_j $ and $ s_k $ such that $ s_i = s_j + s_k $ . That is, $ s_i $ is the concatenation of $ s_j $ and $ s_k $ . Note that $ j $ can be equal to $ k $ . Recall that the concatenation of strings $ s $ and $ t $ is $ s + t = s_1 s_2 \dots s_p t_1 t_2 \dots t_q $ , where $ p $ and $ q $ are the lengths of strings $ s $ and $ t $ respectively. For example, concatenation of "code" and "forces" is "codeforces".

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \leq t \leq 10^4 $ ) — the number of test cases. The first line of each test case contains a single integer $ n $ ( $ 1 \leq n \leq 10^5 $ ) — the number of strings. Then $ n $ lines follow, the $ i $ -th of which contains non-empty string $ s_i $ of length at most $ \mathbf{8} $ , consisting of lowercase English letters. Among the given $ n $ strings, there may be equal (duplicates). The sum of $ n $ over all test cases doesn't exceed $ 10^5 $ .

输出格式


For each test case, output a binary string of length $ n $ . The $ i $ -th bit should be $ \texttt{1} $ if there exist two strings $ s_j $ and $ s_k $ where $ s_i = s_j + s_k $ , and $ \texttt{0} $ otherwise. Note that $ j $ can be equal to $ k $ .

输入输出样例

输入样例 #1

3
5
abab
ab
abc
abacb
c
3
x
xx
xxx
8
codeforc
es
codes
cod
forc
forces
e
code

输出样例 #1

10100
011
10100101

说明

In the first test case, we have the following: - $ s_1 = s_2 + s_2 $ , since $ \texttt{abab} = \texttt{ab} + \texttt{ab} $ . Remember that $ j $ can be equal to $ k $ . - $ s_2 $ is not the concatenation of any two strings in the list. - $ s_3 = s_2 + s_5 $ , since $ \texttt{abc} = \texttt{ab} + \texttt{c} $ . - $ s_4 $ is not the concatenation of any two strings in the list. - $ s_5 $ is not the concatenation of any two strings in the list. Since only $ s_1 $ and $ s_3 $ satisfy the conditions, only the first and third bits in the answer should be $ \texttt{1} $ , so the answer is $ \texttt{10100} $ .

Input

题意翻译

给出 $n$ 个字符串 $s_1,s_2\cdots s_n$ 每个字符串最多长 $8$,问对于每个 $s_i(1 \le i \le n)$ ,是否存在两个字符串 $s_j,s_k(1 \le j,k \le n)$($j$ 可能等于 $k$)使得 $s_i=s_j+s_k$ ,即 $s_i$ 可以由 $s_j,s_k$ 拼接得到。若存在,输出 $1$,否则输出 $0$。共 $t$ 组数据。

Output

题目大意:
给定n个长度最多为8的字符串s1, s2, …, sn。对于每个字符串si,判断是否存在两个字符串sj和sk,使得si=sj+sk,即si可以由sj和sk拼接得到。如果存在,输出1,否则输出0。共有t组数据。

输入输出数据格式:
输入格式:
第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。
每个测试用例的第一行包含一个整数n(1≤n≤10^5)——字符串的数量。
接下来n行,第i行包含一个长度最多为8的非空字符串si,由小写英文字母组成。在给定的n个字符串中,可能存在相等的(重复的)。
所有测试用例的n之和不超过10^5。

输出格式:
对于每个测试用例,输出一个长度为n的二进制字符串。如果存在两个字符串sj和sk,使得si=sj+sk,则第i位为1,否则为0。注意,j可以等于k。

输入输出样例:
输入样例 #1:
3
5
abab
ab
abc
abacb
c
3
x
xx
xxx
8
codeforc
es
codes
cod
forc
forces
e
code

输出样例 #1:
10100
011
10100101题目大意: 给定n个长度最多为8的字符串s1, s2, …, sn。对于每个字符串si,判断是否存在两个字符串sj和sk,使得si=sj+sk,即si可以由sj和sk拼接得到。如果存在,输出1,否则输出0。共有t组数据。 输入输出数据格式: 输入格式: 第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。 每个测试用例的第一行包含一个整数n(1≤n≤10^5)——字符串的数量。 接下来n行,第i行包含一个长度最多为8的非空字符串si,由小写英文字母组成。在给定的n个字符串中,可能存在相等的(重复的)。 所有测试用例的n之和不超过10^5。 输出格式: 对于每个测试用例,输出一个长度为n的二进制字符串。如果存在两个字符串sj和sk,使得si=sj+sk,则第i位为1,否则为0。注意,j可以等于k。 输入输出样例: 输入样例 #1: 3 5 abab ab abc abacb c 3 x xx xxx 8 codeforc es codes cod forc forces e code 输出样例 #1: 10100 011 10100101

加入题单

算法标签: