시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
0.75 초 (추가 시간 없음) | 256 MB | 4 | 1 | 1 | 100.000% |
You are given an infinite line covered with a periodically repeating string $A$ (there are infinitely many concatenated copies of the string $A$ in the line). The line doesn't have a beginning or an end. You are given a set $S$ with $M$ strings. You need to build new string $B$ as concatanation of strings from $S$. String $B$ must satisfy the following conditions:
You can use the same string from $S$ several times, but every time you count it as new string. You can concatenate all strings in any order, but you are not allowed to change the order of letters in the string. In case there is no proper way to build some string $B$, print $-1$.
Print one integer --- minimum number of string instances from $S$ needed to build string $B$.
baabaa 3 a b c
3
You can use one string "b
" and two strings "a
", to build $B$ = "aba
":