DNA string
Time limit2sMemory limit512 MB
Given a DNA string S, find the shortest string over A, C, G, T that never occurs as a contiguous substring of S, breaking ties lexicographically.
- Level
Medium5 of 10
- Topics
- String, String matching, Brute force
- Solved
- No attempts yet
Problem
A DNA string is a string made of the letters A, C, G, T only.
Yeongseon hired the biologist Hyobin to study human genes. The DNA that Hyobin studies is a string . Hyobin wants to find the shortest DNA string that never appears as a contiguous part of .
Several shortest answers can exist. In that case only the lexicographically smallest one counts as correct. The letters are ordered A, C, G, T.
For example, take = "AGGTCTA". Each of the length 1 strings A, C, G, T appears in , so the answer has length at least 2. Among the strings of length 2, "AA" does not appear in , and no string of length 2 comes before "AA" in lexicographic order, so the answer is "AA". "AG" cannot be the answer because it appears in , and "AAA" cannot be the answer because an answer of length 2 exists.
Given , write a program that finds the answer.
Input
The first line contains the string . consists of the letters A, C, G, T only, and its length is between 1 and 2,000.
Output
Print the shortest DNA string that never appears as a contiguous part of . If several such strings exist, print the lexicographically smallest one. The letters are ordered A, C, G, T.