eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Palindromic DNA

Palindromic DNA

A G T C A A DNA sequence is composed of a series of four possible nucleobases, namely Adenine, Guanine, Thymine and Cytosine; we will refer to each of these bases by their initial. For our purposes, nucleobases have an associated cyclic ``order'': is followed by , which in turn is followed by , which is followed by , which is followed by again. State-of-the-art research in genomics has revealed the startling fact that many diseases are caused by certain subsequences of bases not forming a palindromic sequence! Your mission as a leading researcher at ICPC laboratories is to take a DNA string \textit{S} and a series of subsets \textit{P}_1,..., \textit{P}_t of indices to characters (nucleobases) in \textit{S}, and transform \textit{S} so that each of the restrictions of the resulting string to \textit{P}_1,..., \textit{P}_t are palindromic. (The restriction of \textit{S} to a subset \textit{P} = \{\textit{i}_1, \textit{i}_2,..., \textit{i}_k\} of indices, where 0 ≤ \textit{i}_1 < \textit{i}_2 <...< \textit{i}_k < | \textit{S}|, is the string \textit{S}_i1\textit{S}_i2...\textit{S}_ik). It is possible to inspect any base of \textit{S} at will, but only three transformations can be applied to a base: \begin{enumerate} \item Leave it unaltered. \item Increase it by 1 in the cyclic order of nucleobases (e.g. turn C into A ). \item Decrease it by 1 (e.g. turn T into G ). \end{enumerate} Moreover, owing to limitations of current technology, it is impossible to modify two bases in consecutive positions of the sequence. Is our goal achievable? AGTAT GG GG GTG By way of example, consider DNA sequence . Number positions starting from 0, and suppose we have the three subsets \textit{P}_1 = \{1, 4\}, \textit{P}_2 = \{0, 1\} and \textit{P}_3 = \{0, 2, 4\}. One solution is to increase the first character and decrease the last, yielding \textit{S'} = GGTAG. The restrictions of \textit{S'} to \textit{P}_1, \textit{P}_2 and \textit{P}_3 are , and , respectively; all of them are palindromic. CATGC T One case where no solution is possible is when the string is , and we require the subsequences determined by positions \{0, 3\} and \{3, 4\} be palindromic. Here, characters 3, 0 and 4 would all need to become a . But this entails modifying consecutive characters 3 and 4, which is not allowed. \InputFile ACGT The first line of each test case has two integers \textbf{N} and \textbf{T} (\textbf{1 ≤ N ≤ 10 000}, \textbf{1 ≤ T ≤ 6 000}), the sequence length and number of subsets to consider. The next line contains the DNA sequence of length \textit{N}, all of whose characters are in . The subsets are described by the following \textbf{T} lines. Each line starts by "\textbf{L:}", where \textbf{L} (\textbf{0 ≤ L ≤ N}) is the number of positions in the subset, and is followed by \textbf{T} distinct integers between \textbf{0} and \textbf{N}-\textbf{1} in increasing order. Subsets may overlap partially or totally. A blank line separates different test cases. The input file is terminated by a line containing '\textbf{0 0}'. \OutputFile In a single line per test case, print '\textbf{YES}' if the task is solvable and '\textbf{NO}' otherwise.
Лимит времени 10 секунд
Лимит использования памяти 256 MiB
Входные данные #1
5 3
AGTAT
2: 1 4
2: 0 1
3: 0 2 4

5 3
CATGC
0:
2: 0 3
2: 3 4

0 0
Выходные данные #1
YES
NO