#5416. Problem 3. Swap to Win
Problem 3. Swap to Win
Problem 3. Swap to Win
USACO 2026 Third Contest, Bronze
Farmer John has a favorite string with characters. He also has strings each with characters ().
FJ can perform the following two types of operations:
- FJ chooses any string and two indices and . Then, he swaps the 'th and 'th character of ().
- FJ chooses two strings and and an index . Then, he swaps the 'th characters of and ().
His goal is to make equal to . Find any series of operations that fulfills his goal. Because FJ is in a hurry, he only has time to perform a total of operations. The inputs guarantee that it is possible to fulfill FJ's goal.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains (), the number of independent tests. Each test is specified in the following format:
The first line contains and .
The second line contains .
Then, lines follow, the 'th of which contains .
The inputs will guarantee that it is possible to fulfill FJ's goal. All strings contain lowercase English letters (a-z).
OUTPUT FORMAT (print output to the terminal / stdout):
The output for each test should be as follows:
On the first line, output an integer , the number of operations you will perform. must be a non-negative integer less than or equal to .
Then, output lines, denoting the operations you will perform in sequential order. Each line should be one of the following:
SAMPLE INPUT:
3 3 6 banana nabana banana nnbaaa 5 3 abc def bca ghi jkl mno 3 5 abcde abcde abcde zzzzz
SAMPLE OUTPUT:
3 2 1 2 1 1 1 3 5 2 1 2 5 5 1 2 1 3 2 1 2 1 1 2 2 3 2 1 2 2 2 1 2 3 0
Here is how changes according to the first test's output (with letters swapped in uppercase):
nabana Babana baNaBa banaNa banana -> Nanana -> nanana -> nanaBa nnbaaa nnbaaa nnbaaa nnbaaa
After all three operations, .
SCORING: Inputs 2-6: Inputs 7-12: No additional constraints.
Problem credits: Chongtian Ma