CF1384A.Common Prefixes

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The length of the longest common prefix of two strings s=s1s2…sns = s_1 s_2 \ldots s_n and t=t1t2…tmt = t_1 t_2 \ldots t_m is defined as the maximum integer kk (0≤k≤min(n,m)0 \le k \le min(n,m)) such that s1s2…sks_1 s_2 \ldots s_k equals t1t2…tkt_1 t_2 \ldots t_k.

Koa the Koala initially has n+1n+1 strings s1,s2,…,sn+1s_1, s_2, \dots, s_{n+1}.

For each ii (1≤i≤n1 \le i \le n) she calculated aia_i — the length of the longest common prefix of sis_i and si+1s_{i+1}.

Several days later Koa found these numbers, but she couldn't remember the strings.

So Koa would like to find some strings s1,s2,…,sn+1s_1, s_2, \dots, s_{n+1} which would have generated numbers a1,a2,…,ana_1, a_2, \dots, a_n. Can you help her?

If there are many answers print any. We can show that answer always exists for the given constraints.

两个字符串 s=s1s2…sns = s_1 s_2 \ldots s_n 和 t=t1t2…tmt = t_1 t_2 \ldots t_m 的最长公共前缀长度定义为满足 s1s2…sk=t1t2…tks_1 s_2 \ldots s_k = t_1 t_2 \ldots t_k 的最大整数 kk(其中 0≤k≤min⁡(n,m)0 \le k \le \min(n,m))。

考拉熊 Koa 最初有 n+1n+1 个字符串 s1,s2,…,sn+1s_1, s_2, \dots, s_{n+1}。

对每个 ii(1≤i≤n1 \le i \le n),她计算了 aia_i —— 即 sis_i 与 si+1s_{i+1} 的最长公共前缀长度。

几天后,Koa 找到了这些数值 aia_i,但她已记不得原来的字符串了。

因此,Koa 希望找出一组字符串 s1,s2,…,sn+1s_1, s_2, \dots, s_{n+1},使得它们能生成给定的数值 a1,a2,…,ana_1, a_2, \dots, a_n。你能帮她吗?

若存在多个解,输出任意一个即可。可以证明:在题目给定的约束条件下,解一定存在。

输入格式

Each test contains multiple test cases. The first line contains tt (1≤t≤1001 \le t \le 100) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001 \le n \le 100) — the number of elements in the list aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤500 \le a_i \le 50) — the elements of aa.

It is guaranteed that the sum of nn over all test cases does not exceed 100100.

每个测试包含多个测试用例。第一行包含 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 列表 aa 中的元素个数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤500 \le a_i \le 50)—— aa 的元素。

保证所有测试用例的 nn 之和不超过 100100。

输出格式

For each test case:

Output n+1n+1 lines. In the ii-th line print string sis_i (1≤∣si∣≤2001 \le |s_i| \le 200), consisting of lowercase Latin letters. Length of the longest common prefix of strings sis_i and si+1s_{i+1} has to be equal to aia_i.

If there are many answers print any. We can show that answer always exists for the given constraints.

对于每个测试用例:

输出 n+1n+1 行。在第 ii 行输出字符串 sis_i(1≤∣si∣≤2001 \le |s_i| \le 200),该字符串仅由小写拉丁字母组成。字符串 sis_i 与 si+1s_{i+1} 的最长公共前缀长度必须等于 aia_i。

若存在多个合法答案,输出任意一个即可。可以证明:在给定约束条件下,答案一定存在。

输入输出样例

  • 输入#1

    4
    4
    1 2 4 2
    2
    5 3
    3
    1 3 1
    3
    0 0 0

    输出#1

    aeren
    ari
    arousal
    around
    ari
    monogon
    monogamy
    monthly
    kevinvu
    kuroni
    kurioni
    korone
    anton
    loves
    adhoc
    problems

说明/提示

In the 11-st test case one of the possible answers is s=[aeren,ari,arousal,around,ari]s = [aeren, ari, arousal, around, ari].

Lengths of longest common prefixes are:

  • Between aeren\color{red}{a}eren and ari\color{red}{a}ri →1\rightarrow 1
  • Between ari\color{red}{ar}i and arousal\color{red}{ar}ousal →2\rightarrow 2
  • Between arousal\color{red}{arou}sal and around\color{red}{arou}nd →4\rightarrow 4
  • Between around\color{red}{ar}ound and ari\color{red}{ar}i →2\rightarrow 2

在第 11 个测试用例中,一种可能的答案是 s=[aeren,ari,arousal,around,ari]s = [aeren, ari, arousal, around, ari]。

最长公共前缀的长度分别为:

  • aeren\color{red}{a}eren 与 ari\color{red}{a}ri 之间 →1\rightarrow 1
  • ari\color{red}{ar}i 与 arousal\color{red}{ar}ousal 之间 →2\rightarrow 2
  • arousal\color{red}{arou}sal 与 around\color{red}{arou}nd 之间 →4\rightarrow 4
  • around\color{red}{ar}ound 与 ari\color{red}{ar}i 之间 →2\rightarrow 2

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

首页