CF936C.Lock Puzzle

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm!

Of course, there is a code lock is installed on the safe. The lock has a screen that displays a string of n lowercase Latin letters. Initially, the screen displays string s. Whitfield and Martin found out that the safe will open when string t will be displayed on the screen.

The string on the screen can be changed using the operation «shift x». In order to apply this operation, explorers choose an integer x from 0 to n inclusive. After that, the current string p = αβ changes to β_R_α, where the length of β is x, and the length of α is n - x. In other words, the suffix of the length x of string p is reversed and moved to the beginning of the string. For example, after the operation «shift 4» the string «abcacb» will be changed with string «bcacab », since α = ab, β = cacb, β_R_ = bcac.

Explorers are afraid that if they apply too many operations «shift», the lock will be locked forever. They ask you to find a way to get the string t on the screen, using no more than 6100 operations.

欢迎来到另一个破解密码锁的任务!探险家惠特菲尔德(Whitfield)和马丁(Martin)发现了一个不同寻常的保险箱,据传闻,其中藏有数不清的财富,甚至包括离散对数问题的解!

当然,保险箱上安装了一个密码锁。锁上有一个屏幕,显示一串由 n 个小写拉丁字母组成的字符串。初始时,屏幕上显示字符串 s。惠特菲尔德和马丁得知:当屏幕上显示字符串 t 时,保险箱便会打开。

屏幕上的字符串可通过操作「shift x」进行更改。要执行该操作,探险家需选择一个整数 x(满足 0≤x≤n0 \le x \le n)。此后,当前字符串 p=αβp = \alpha\beta 将变为 βRα\beta_R\alpha,其中 β\beta 的长度为 xx,α\alpha 的长度为 n−xn - x。换言之,字符串 pp 的长度为 xx 的后缀被反转后移至字符串开头。例如,对字符串 abcacb 执行「shift 4」操作后,字符串将变为 bcacab,因为 α=ab\alpha = \text{ab},β=cacb\beta = \text{cacb},而 βR=bcac\beta_R = \text{bcac}。

探险家担心,若执行过多的「shift」操作,锁将永久锁定。他们请你找出一种方法,仅用不超过 6100 次操作,使屏幕上最终显示字符串 t。

输入格式

The first line contains an integer n, the length of the strings s and t (1 ≤ n ≤ 2 000).

After that, there are two strings s and t, consisting of n lowercase Latin letters each.

第一行包含一个整数 nn,表示字符串 ss 和 tt 的长度(1 ≤ n ≤ 2 0001 ≤ n ≤ 2\,000)。

随后是两个字符串 ss 和 tt,每个均由 nn 个小写拉丁字母组成。

输出格式

If it is impossible to get string t from string s using no more than 6100 operations «shift», print a single number  - 1.

Otherwise, in the first line output the number of operations k (0 ≤ k ≤ 6100). In the next line output k numbers x__i corresponding to the operations «shift x__i» (0 ≤ x__i ≤ n) in the order in which they should be applied.

如果无法通过至多 6100 次「移位」操作将字符串 ss 变为字符串 tt,则输出单个数字 −1-1。

否则,第一行输出操作次数 kk(0 ≤ k ≤ 61000 \le k \le 6100);第二行输出 kk 个数 xix_i,分别对应「移位 xix_i」操作(0 ≤ xi ≤ n0 \le x_i \le n),按其执行顺序排列。

输入输出样例

  • 输入#1

    6
    abacbb
    babcba

    输出#1

    4
    6 3 2 3
  • 输入#2

    3
    aba
    bba

    输出#2

    -1

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

首页