Logo
(追記) (追記ここまで)

23505번 - Rats 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.75 초 (추가 시간 없음) 256 MB1411100.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:

  • After covering a new empty infinite line with infinitely many concatenations of the string $B,ドル the line should be identical with string $A$.
  • In case there are several valid strings $B$ or several valid constructions of the string $B,ドル you should choose $B$ and its construction which minimize number of strings used from $S$.

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$.

입력

  • The first line contains string $A$ $(1\leq |A| \leq 500)$.
  • The second line contains the integer $M$ $(1 \leq M \leq 10^5),ドル number of strings in set $S$.
  • Each of next $M$ lines contains one string from $S,ドル $i$-th line contains string $L_i$ $(1 \leq |L_i| \leq |A|)$. Sum of lengths of strings from set $S$ is smaller than 10ドル^6$ $(\sum_{i=1}^{M} |L_i| \leq 10^6)$.

출력

Print one integer --- minimum number of string instances from $S$ needed to build string $B$.

제한

예제 입력 1

baabaa
3
a
b
c

예제 출력 1

3

힌트

You can use one string "b" and two strings "a", to build $B$ = "aba":

  • ...baabaabaabaa...
  • .....abaabaabaaba...

출처

Contest > Open Cup > 2019/2020 Season > Stage 19: The Grand Prix of Serbia G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /