#P15572. [USACO26FEB] Swap to Win B

[USACO26FEB] Swap to Win B

题目描述

Farmer John has a favorite string tt with MM characters. He also has NN strings s1,s2,,sNs_1, s_2, \ldots, s_N each with MM characters (1N,M10001 \leq N, M \leq 1000).

FJ can perform the following two types of operations:

  • FJ chooses any string sxs_x and two indices pp and qq. Then, he swaps the pp'th and qq'th character of sxs_x (1xN,1p,qM1\le x\le N, 1\le p,q\le M).
  • FJ chooses two strings sxs_x and sys_y and an index kk. Then, he swaps the kk'th characters of sxs_x and sys_y (1x,yN,1kM1\le x,y\le N, 1\le k\le M).

His goal is to make s1s_1 equal to tt. Find any series of operations that fulfills his goal. Because FJ is in a hurry, he only has time to perform a total of 2M2M operations. The inputs guarantee that it is possible to fulfill FJ's goal.

输入格式

The first line contains TT (1T101\le T\le 10), the number of independent tests. Each test is specified in the following format:

The first line contains NN and MM.

The second line contains tt.

Then, NN lines follow, the ii'th of which contains sis_i.

The inputs will guarantee that it is possible to fulfill FJ's goal. All strings contain lowercase English letters (a-z).

输出格式

The output for each test should be as follows: On the first line, output an integer KK, the number of operations you will perform. KK must be a non-negative integer less than or equal to 2M2M.

Then, output KK lines, denoting the operations you will perform in sequential order. Each line should be one of the following:

  • 1 x p q\texttt{1 x p q}
  • 2 x y k\texttt{2 x y k}
3
3 6
banana
nabana
banana
nnbaaa
5 3
abc
def
bca
ghi
jkl
mno
3 5
abcde
abcde
abcde
zzzzz
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 ss 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, s1=ts_1=t.

SCORING:

  • Inputs 2-6: N,M100N, M \le 100
  • Inputs 7-12: No additional constraints.

Problem credits: Chongtian Ma