CF868D.Huge Strings

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given n strings _s_1, s_2, ..., s__n consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation s__a__i__s__b__i is saved into a new string s__n + i (the operations are numbered starting from 1). After each operation you need to find the maximum positive integer k such that all possible strings consisting of 0 and 1 of length k (there are 2_k such strings) are substrings of the new string. If there is no such k, print 0.

给你 nn 个仅由字符 0 和 1 组成的字符串 s1,s2,…,sns_1, s_2, \dots, s_n。接下来执行 mm 次操作,每次操作将两个已存在的字符串拼接成一个新字符串。在第 ii 次操作中,将字符串 saisbis_{a_i}s_{b_i}(即 sais_{a_i} 与 sbis_{b_i} 的拼接)保存为新字符串 sn+is_{n+i}(操作编号从 1 开始)。每次操作后,你需要找出最大的正整数 kk,使得所有长度为 kk 的、由 0 和 1 构成的字符串(共 2k2^k 个)均为该新字符串的子串。若不存在这样的 kk,则输出 0。

输入格式

The first line contains single integer n (1 ≤ n ≤ 100) — the number of strings. The next n lines contain strings _s_1, _s_2, ..., s__n (1 ≤ |s__i| ≤ 100), one per line. The total length of strings is not greater than 100.

The next line contains single integer m (1 ≤ m ≤ 100) — the number of operations. m lines follow, each of them contains two integers a__i abd b__i (1 ≤ a__i, b__i ≤ n + i - 1) — the number of strings that are concatenated to form s__n + i.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 字符串的数量。接下来的 nn 行每行包含一个字符串 s1, s2, …, sns_1,\ s_2,\ \dots,\ s_n(1≤∣si∣≤1001 \leq |s_i| \leq 100)。所有字符串的总长度不超过 100100。

下一行包含一个整数 mm(1≤m≤1001 \leq m \leq 100)—— 操作的数量。随后有 mm 行,每行包含两个整数 aia_i 和 bib_i(1≤ai, bi≤n+i−11 \leq a_i,\ b_i \leq n + i - 1),表示用于构成 sn+is_{n+i} 的两个字符串的编号(即 sn+i=sai+sbis_{n+i} = s_{a_i} + s_{b_i})。

输出格式

Print m lines, each should contain one integer — the answer to the question after the corresponding operation.

输出 m 行,每行应包含一个整数——对应操作后问题的答案。

输入输出样例

  • 输入#1

    5
    01
    10
    101
    11111
    0
    3
    1 2
    6 5
    4 4

    输出#1

    1
    2
    0

说明/提示

On the first operation, a new string "0110" is created. For k = 1 the two possible binary strings of length k are "0" and "1", they are substrings of the new string. For k = 2 and greater there exist strings of length k that do not appear in this string (for k = 2 such string is "00"). So the answer is 1.

On the second operation the string "01100" is created. Now all strings of length k = 2 are present.

On the third operation the string "1111111111" is created. There is no zero, so the answer is 0.

第一次操作创建了一个新字符串“0110”。当 k=1k = 1 时,所有长度为 kk 的二进制字符串(即“0”和“1”)均为此新字符串的子串;而当 k=2k = 2 及更大时,存在某些长度为 kk 的字符串未在此字符串中出现(例如当 k=2k = 2 时,“00”即为一个未出现的字符串)。因此答案为 1。

第二次操作创建了字符串“01100”。此时所有长度为 k=2k = 2 的二进制字符串均已出现。

第三次操作创建了字符串“1111111111”。该字符串中不含字符“0”,因此答案为 0。

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

首页