CF1703D.Double Strings

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn strings s1,s2,…,sns_1, s_2, \dots, s_n of length at most 8\mathbf{8}.

For each string sis_i, determine if there exist two strings sjs_j and sks_k such that si=sj+sks_i = s_j + s_k. That is, sis_i is the concatenation of sjs_j and sks_k. Note that jj can be equal to kk.

Recall that the concatenation of strings ss and tt is s+t=s1s2…spt1t2…tqs + t = s_1 s_2 \dots s_p t_1 t_2 \dots t_q, where pp and qq are the lengths of strings ss and tt respectively. For example, concatenation of "code" and "forces" is "codeforces".

给你 nn 个长度不超过 8\mathbf{8} 的字符串 s1,s2,…,sns_1, s_2, \dots, s_n。

对每个字符串 sis_i,判断是否存在两个字符串 sjs_j 和 sks_k,使得 si=sj+sks_i = s_j + s_k。即 sis_i 是 sjs_j 与 sks_k 的拼接。注意:jj 可以等于 kk。

回顾一下,字符串 ss 与 tt 的拼接定义为 s+t=s1s2…spt1t2…tqs + t = s_1 s_2 \dots s_p t_1 t_2 \dots t_q,其中 pp 和 qq 分别是字符串 ss 和 tt 的长度。例如,“code” 与 “forces” 的拼接结果是 “codeforces”。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1051 \leq n \leq 10^5) — the number of strings.

Then nn lines follow, the ii-th of which contains non-empty string sis_i of length at most 8\mathbf{8}, consisting of lowercase English letters. Among the given nn strings, there may be equal (duplicates).

The sum of nn over all test cases doesn't exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 字符串的数量。

接下来是 nn 行,其中第 ii 行包含一个非空字符串 sis_i,其长度至多为 8\mathbf{8},且仅由小写英文字母组成。在给定的 nn 个字符串中,可能存在相等的字符串(即重复项)。

所有测试用例的 nn 值之和不超过 10510^5。

输出格式

For each test case, output a binary string of length nn. The ii-th bit should be 1\texttt{1} if there exist two strings sjs_j and sks_k where si=sj+sks_i = s_j + s_k, and 0\texttt{0} otherwise. Note that jj can be equal to kk.

对于每个测试用例,输出一个长度为 nn 的二进制字符串。其中第 ii 位应为 1\texttt{1},当且仅当存在两个字符串 sjs_j 和 sks_k,使得 si=sj+sks_i = s_j + s_k;否则为 0\texttt{0}。注意,jj 可以等于 kk。

输入输出样例

  • 输入#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:

  • s1=s2+s2s_1 = s_2 + s_2, since abab=ab+ab\texttt{abab} = \texttt{ab} + \texttt{ab}. Remember that jj can be equal to kk.
  • s2s_2 is not the concatenation of any two strings in the list.
  • s3=s2+s5s_3 = s_2 + s_5, since abc=ab+c\texttt{abc} = \texttt{ab} + \texttt{c}.
  • s4s_4 is not the concatenation of any two strings in the list.
  • s5s_5 is not the concatenation of any two strings in the list.

Since only s1s_1 and s3s_3 satisfy the conditions, only the first and third bits in the answer should be 1\texttt{1}, so the answer is 10100\texttt{10100}.

在第一个测试用例中,我们有如下情况:

  • s1=s2+s2s_1 = s_2 + s_2,因为 abab=ab+ab\texttt{abab} = \texttt{ab} + \texttt{ab}。注意 jj 可以等于 kk。
  • s2s_2 不能表示为列表中任意两个字符串的拼接。
  • s3=s2+s5s_3 = s_2 + s_5,因为 abc=ab+c\texttt{abc} = \texttt{ab} + \texttt{c}。
  • s4s_4 不能表示为列表中任意两个字符串的拼接。
  • s5s_5 不能表示为列表中任意两个字符串的拼接。

由于只有 s1s_1 和 s3s_3 满足条件,因此答案中仅第一位和第三位应为 1\texttt{1},故答案为 10100\texttt{10100}。

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

首页