QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#12883. DNA 进化

Statistics

Fox Ciel 刚有了一个新生儿(Fox Jaro)。Fox Ciel 一直对遗传学和 DNA 序列很感兴趣,他想把他所学到的知识应用到他的儿子身上!DNA 由核苷酸序列组成。核苷酸有四种:A、C、G 和 T。DNA 序列从父母传给孩子,但每个新生儿会比他的父亲多出一些核苷酸(新核苷酸被添加到序列的开头)。例如,Fox Ciel 的 DNA 是 CACAA,他儿子 Jaro 的 DNA 是 ACACAA(注意,Jaro 比 Ciel 多出的 A 被添加到了从 Ciel 那里继承的 DNA 之前)。

Ciel 一直在思考他的祖先以及他的新生儿长得有多像他们。他注意到,他的儿子和他的某位祖先之间的相似度与他们共同字符的最大公共前缀长度成正比,他将其称为相似度系数。他写下了所有祖先的 DNA,并计算了他们每个人与 Jaro 的 DNA (ACACAA) 之间的相似度系数,然后将这些记录在下表中(参见说明以获取正式定义)。

ACACAA 6
CACAA 0
ACAA 3
CAA 0
AA 1
A 1

Rabbit Hanako 弄乱了 Ciel 的笔记,删除了 Jaro 的 DNA 序列。如果 Ciel 发现了这一点,他会攻击 Hanako 并吃掉他!你能帮 Hanako 在 Ciel 发现之前尽快恢复这个 DNA 序列吗?

输入格式

你的程序将在一个或多个测试用例上进行测试。输入的第一行是一个整数 $T$,表示测试用例的数量($1 \le T \le 100$)。接下来是 $T$ 个测试用例。

每个测试用例由一行以空格分隔的整数给出。该行第一个整数表示 DNA 序列 $N$ 的长度,随后是 $N$ 个整数 $a_i$,表示位置 $i$ 的相似度系数,其中 $0 \le i < n$($1 \le N \le 10^5$ 且 $0 \le a_i \le 10^5$)。

输出格式

对于每个测试用例,打印一行包含 DNA 序列 $S$。如果有多个有效的序列,请打印字典序最小的一个。如果不存在有效的序列,且 Hanako 无法恢复该序列,则打印 "Impossible"(不带引号)。

字符串 $x$ 在字典序上小于字符串 $y$,如果 $x$ 是 $y$ 的前缀,或者存在某个 $i$($1 \le i \le \min(|x|, |y|)$),使得 $x_i < y_i$,且对于所有 $j$($1 \le j < i$),$x_j = y_j$。

样例

输入 1

3
1 1
3 3 0 1
3 3 3 3

输出 1

A
ACA
Impossible

说明

形式上,给定一个长度为 $n$ 的字符串 $S$(DNA),说明中包含一个数组 $A$,其中 $A[i]$ 是从 $S[i]$ 开始的最长子串,且该子串同时也是 $S$ 的前缀的长度。换句话说,它是满足对于所有 $0 \le j < k$ 都有 $S[j] = S[i + j]$ 的最大 $k$。

Figure 1. Similarity coefficients table

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.