CF1015B.Obtaining the String
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two strings s and t. Both strings have length n and consist of lowercase Latin letters. The characters in the strings are numbered from 1 to n.
You can successively perform the following move any number of times (possibly, zero):
- swap any two adjacent (neighboring) characters of s (i.e. for any i=1,2,…,n−1 you can swap si and si+1).
You can't apply a move to the string t. The moves are applied to the string s one after another.
Your task is to obtain the string t from the string s. Find any way to do it with at most 104 such moves.
You do not have to minimize the number of moves, just find any sequence of moves of length 104 or less to transform s into t.
给你两个字符串 s 和 t。两个字符串的长度均为 n,且均由小写拉丁字母组成。字符串中的字符编号从 1 到 n。
你可以任意多次(包括零次)依次执行以下操作:
- 交换 s 中任意两个相邻(即位置相邻)的字符(即对任意 i=1,2,…,n−1,可交换 si 与 si+1)。
你不能对字符串 t 执行任何操作。所有操作均依次作用于字符串 s。
你的任务是通过上述操作将字符串 s 变为字符串 t。请找出一种方案,使得变换过程至多使用 104 次操作。
你无需最小化操作次数,只需找到一种长度不超过 104 的操作序列,将 s 变为 t 即可。
输入格式
The first line of the input contains one integer n (1≤n≤50) — the length of strings s and t.
The second line of the input contains the string s consisting of n lowercase Latin letters.
The third line of the input contains the string t consisting of n lowercase Latin letters.
输入的第一行包含一个整数 n(1≤n≤50)—— 表示字符串 s 和 t 的长度。
输入的第二行包含字符串 s,由 n 个小写拉丁字母组成。
输入的第三行包含字符串 t,由 n 个小写拉丁字母组成。
输出格式
If it is impossible to obtain the string t using moves, print "-1".
Otherwise in the first line print one integer k — the number of moves to transform s to t. Note that k must be an integer number between 0 and 104 inclusive.
In the second line print k integers cj (1≤cj<n), where cj means that on the j-th move you swap characters scj and scj+1.
If you do not need to apply any moves, print a single integer 0 in the first line and either leave the second line empty or do not print it at all.
如果无法通过移动操作得到字符串 t,则输出 -1。
否则,第一行输出一个整数 k —— 将 s 变换为 t 所需的移动次数。注意:k 必须是介于 0 和 104(含)之间的整数。
第二行输出 k 个整数 cj(1≤cj<n),其中 cj 表示在第 j 次移动中交换字符 scj 和 scj+1。
如果无需执行任何移动,则第一行仅输出整数 0,第二行可留空或完全不输出。
输入输出样例
输入#1
6 abcdef abdfec
输出#1
4 3 5 4 5
输入#2
4 abcd accd
输出#2
-1
说明/提示
In the first example the string s changes as follows: "abcdef" → "abdcef" → "abdcfe" → "abdfce" → "abdfec".
In the second example there is no way to transform the string s into the string t through any allowed moves.
在第一个例子中,字符串 s 的变化过程如下:“abcdef” → “abdcef” → “abdcfe” → “abdfce” → “abdfec”。
在第二个例子中,无法通过任何允许的操作将字符串 s 变换为字符串 t。
输入解题思路,AI测评打分。不知道怎么写?