QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 512 MB Puntuación total: 100

#11697. 洗牌

Estadísticas

给定一个长度为偶数的字符串 $s = s_1 \dots s_n$,我们定义洗牌操作(shuffle operation),该操作根据以下规则将字符串转换为新字符串:

$$\text{shuffle}(s) = s_1 s_3 \dots s_{n-1} s_2 s_4 \dots s_n$$

例如,$\text{shuffle}(\text{abcdef}) = \text{acebdf}$。

给定两个长度相等且为偶数的字符串 $s$ 和 $t$。你需要对 $s$ 进行多少次洗牌操作才能得到 $t$?

换句话说,求最小的 $k$,使得 $\underbrace{\text{shuffle}(\text{shuffle}(\dots \text{shuffle}}_{k \text{ times}}(s)\dots)) = t$,如果无论进行多少次操作都无法得到 $t$,则输出 -1。

输入格式

第一行包含字符串 $s$,第二行包含字符串 $t$($|s| = |t|$,$2 \le |s| \le 10^6$,$|s|$ 为偶数)。两个字符串均由小写英文字母组成。

输出格式

输出最小的非负整数 $k$,使得通过对 $s$ 进行 $k$ 次洗牌操作可以得到 $t$(如果 $k=0$ 时相等,则输出 0),如果无法得到,则输出 -1。

样例

样例输入 1

abcdef
aedcbf

样例输出 1

2

样例输入 2

petrozavodsk
poztsvoedark

样例输出 2

3

样例输入 3

qwerty
ytrewq

样例输出 3

-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.