CF91A.Newspaper Headline

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A newspaper is published in Walrusland. Its heading is _s_1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a new word _s_2. It is considered that when Fangy erases some letter, there's no whitespace formed instead of the letter. That is, the string remains unbroken and it still only consists of lowercase Latin letters.

For example, the heading is "abc". If we take two such headings and glue them one to the other one, we get "abcabc". If we erase the letters on positions 1 and 5, we get a word "bcac".

Which least number of newspaper headings _s_1 will Fangy need to glue them, erase several letters and get word _s_2?

《海象国日报》的报头为字符串 s1s_1,仅由小写拉丁字母组成。小海象 Fangy 想购买若干份该报纸,剪下每份报纸的报头,再将这些报头按顺序首尾粘贴,从而得到一个长字符串。随后,Fangy 从该长字符串中擦除若干个字母,得到一个新的单词 s2s_2。注意:当 Fangy 擦除某个字母时,该位置不会产生空格,即字符串保持连续,且仍仅由小写拉丁字母组成。

例如,报头为 "abc"。若取两份该报头并粘贴在一起,得到 "abcabc";若擦除位置 11 和 55(从 00 开始计数)上的字母,则得到单词 "bcac"。

问:Fangy 至少需要多少份报纸(即至少需要多少个 s1s_1)进行粘贴和擦除操作,才能得到单词 s2s_2?

输入格式

The input data contain two lines. The first line contain the heading _s_1, the second line contains the word _s_2. The lines only consist of lowercase Latin letters (1 ≤ |_s_1| ≤ 104, 1 ≤ |_s_2| ≤ 106).

输入数据包含两行。第一行包含标题 s1s_1,第二行包含单词 s2s_2。每行仅由小写拉丁字母组成(1 ≤ ∣s1∣ ≤ 1041 \le |s_1| \le 10^4,1 ≤ ∣s2∣ ≤ 1061 \le |s_2| \le 10^6)。

输出格式

If it is impossible to get the word _s_2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings _s_1, which Fangy will need to receive the word _s_2.

如果无法通过上述方式得到字符串 s2s_2,则输出 -1(不带引号)。否则,输出 Fangy 为得到字符串 s2s_2 所需的最少报纸标题数 s1s_1。

输入输出样例

  • 输入#1

    abc
    xyz

    输出#1

    -1
  • 输入#2

    abcd
    dabc

    输出#2

    2

输入解题思路,AI测评打分。不知道怎么写?

首页