CF1384A.Common Prefixes
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The length of the longest common prefix of two strings s=s1s2…sn and t=t1t2…tm is defined as the maximum integer k (0≤k≤min(n,m)) such that s1s2…sk equals t1t2…tk.
Koa the Koala initially has n+1 strings s1,s2,…,sn+1.
For each i (1≤i≤n) she calculated ai — the length of the longest common prefix of si and si+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+1 which would have generated numbers a1,a2,…,an. Can you help her?
If there are many answers print any. We can show that answer always exists for the given constraints.
两个字符串 s=s1s2…sn 和 t=t1t2…tm 的最长公共前缀长度定义为满足 s1s2…sk=t1t2…tk 的最大整数 k(其中 0≤k≤min(n,m))。
考拉熊 Koa 最初有 n+1 个字符串 s1,s2,…,sn+1。
对每个 i(1≤i≤n),她计算了 ai —— 即 si 与 si+1 的最长公共前缀长度。
几天后,Koa 找到了这些数值 ai,但她已记不得原来的字符串了。
因此,Koa 希望找出一组字符串 s1,s2,…,sn+1,使得它们能生成给定的数值 a1,a2,…,an。你能帮她吗?
若存在多个解,输出任意一个即可。可以证明:在题目给定的约束条件下,解一定存在。
输入格式
Each test contains multiple test cases. The first line contains t (1≤t≤100) — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤100) — the number of elements in the list a.
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤50) — the elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 100.
每个测试包含多个测试用例。第一行包含 t(1≤t≤100)—— 测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 列表 a 中的元素个数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤50)—— a 的元素。
保证所有测试用例的 n 之和不超过 100。
输出格式
For each test case:
Output n+1 lines. In the i-th line print string si (1≤∣si∣≤200), consisting of lowercase Latin letters. Length of the longest common prefix of strings si and si+1 has to be equal to ai.
If there are many answers print any. We can show that answer always exists for the given constraints.
对于每个测试用例:
输出 n+1 行。在第 i 行输出字符串 si(1≤∣si∣≤200),该字符串仅由小写拉丁字母组成。字符串 si 与 si+1 的最长公共前缀长度必须等于 ai。
若存在多个合法答案,输出任意一个即可。可以证明:在给定约束条件下,答案一定存在。
输入输出样例
输入#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 1-st test case one of the possible answers is s=[aeren,ari,arousal,around,ari].
Lengths of longest common prefixes are:
- Between aeren and ari →1
- Between ari and arousal →2
- Between arousal and around →4
- Between around and ari →2
在第 1 个测试用例中,一种可能的答案是 s=[aeren,ari,arousal,around,ari]。
最长公共前缀的长度分别为:
- aeren 与 ari 之间 →1
- ari 与 arousal 之间 →2
- arousal 与 around 之间 →4
- around 与 ari 之间 →2
输入解题思路,AI测评打分。不知道怎么写?