CF1015B.Obtaining the String

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two strings ss and tt. Both strings have length nn and consist of lowercase Latin letters. The characters in the strings are numbered from 11 to nn.

You can successively perform the following move any number of times (possibly, zero):

  • swap any two adjacent (neighboring) characters of ss (i.e. for any i=1,2,…,n−1i = {1, 2, \dots, n - 1} you can swap sis_i and si+1)s_{i + 1}).

You can't apply a move to the string tt. The moves are applied to the string ss one after another.

Your task is to obtain the string tt from the string ss. Find any way to do it with at most 10410^4 such moves.

You do not have to minimize the number of moves, just find any sequence of moves of length 10410^4 or less to transform ss into tt.

给你两个字符串 ss 和 tt。两个字符串的长度均为 nn,且均由小写拉丁字母组成。字符串中的字符编号从 11 到 nn。

你可以任意多次(包括零次)依次执行以下操作:

  • 交换 ss 中任意两个相邻(即位置相邻)的字符(即对任意 i=1,2,…,n−1i = {1, 2, \dots, n - 1},可交换 sis_i 与 si+1s_{i + 1})。

你不能对字符串 tt 执行任何操作。所有操作均依次作用于字符串 ss。

你的任务是通过上述操作将字符串 ss 变为字符串 tt。请找出一种方案,使得变换过程至多使用 10410^4 次操作。

你无需最小化操作次数,只需找到一种长度不超过 10410^4 的操作序列,将 ss 变为 tt 即可。

输入格式

The first line of the input contains one integer nn (1≤n≤501 \le n \le 50) — the length of strings ss and tt.

The second line of the input contains the string ss consisting of nn lowercase Latin letters.

The third line of the input contains the string tt consisting of nn lowercase Latin letters.

输入的第一行包含一个整数 nn(1≤n≤501 \le n \le 50)—— 表示字符串 ss 和 tt 的长度。

输入的第二行包含字符串 ss,由 nn 个小写拉丁字母组成。

输入的第三行包含字符串 tt,由 nn 个小写拉丁字母组成。

输出格式

If it is impossible to obtain the string tt using moves, print "-1".

Otherwise in the first line print one integer kk — the number of moves to transform ss to tt. Note that kk must be an integer number between 00 and 10410^4 inclusive.

In the second line print kk integers cjc_j (1≤cj<n1 \le c_j \lt n), where cjc_j means that on the jj-th move you swap characters scjs_{c_j} and scj+1s_{c_j + 1}.

If you do not need to apply any moves, print a single integer 00 in the first line and either leave the second line empty or do not print it at all.

如果无法通过移动操作得到字符串 tt,则输出 -1。

否则,第一行输出一个整数 kk —— 将 ss 变换为 tt 所需的移动次数。注意:kk 必须是介于 00 和 10410^4(含)之间的整数。

第二行输出 kk 个整数 cjc_j(1≤cj<n1 \le c_j \lt n),其中 cjc_j 表示在第 jj 次移动中交换字符 scjs_{c_j} 和 scj+1s_{c_j + 1}。

如果无需执行任何移动,则第一行仅输出整数 00,第二行可留空或完全不输出。

输入输出样例

  • 输入#1

    6
    abcdef
    abdfec

    输出#1

    4
    3 5 4 5
  • 输入#2

    4
    abcd
    accd

    输出#2

    -1

说明/提示

In the first example the string ss changes as follows: "abcdef" →\rightarrow "abdcef" →\rightarrow "abdcfe" →\rightarrow "abdfce" →\rightarrow "abdfec".

In the second example there is no way to transform the string ss into the string tt through any allowed moves.

在第一个例子中,字符串 ss 的变化过程如下:“abcdef” →\rightarrow “abdcef” →\rightarrow “abdcfe” →\rightarrow “abdfce” →\rightarrow “abdfec”。

在第二个例子中,无法通过任何允许的操作将字符串 ss 变换为字符串 tt。

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

首页