Let be a string of size . For each , let , and let be the longest prefix of that is also a suffix of (excluding itself). The prefix table for is a vector of integers that stores at the size of .
For instance, let
be "aabaacaabaa". The prefix table in this case is
0 1 2 3 4 5 6 7 8 9 10
| a | a | b | a | a | c | a | a | b | a | a | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 1 | 2 | 0 | 1 | 2 | 3 | 4 | 5 |
For example,
[8]
corresponds to
"aab", the longest proper prefix and proper suffix of
"aabaacaab".
As other examples, the prefix table of "zzzzzz" is , and the prefix table of "ababa" is .
Given a vector of integers, could it be the prefix table of some string?
Input consists of several cases, each with , followed by , …, . You can assume and .
For each case, print “yes” or “no”
depending on whether the given numbers can define the prefix table of
some string. Assume that we use an alphabet with an unlimited number of
different characters.
Author: Salvador Roura
Event: Vint-i-quatrè Concurs de Programació de la UPC -
Final
Date: 2026-10-07
Generation: 2026-10-03T13:38:25.065Z
© Jutge.org, 2006–2026.
https://jutge.org