#include #define MT_N 624 #define MT_M 397 #define MT_MATRIX_A 0x9908b0dfUL #define MT_UPPER_MASK 0x80000000UL #define MT_LOWER_MASK 0x7fffffffUL static unsigned int mt[MT_N]; static int mti = MT_N + 1; void init_genrand(unsigned int s) { mt[0] = s & 0xffffffffUL; for (mti = 1; mti < MT_N; mti++) { mt[mti] = (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); mt[mti] &= 0xffffffffUL; } } unsigned int genrand() { unsigned int y; static unsigned int mag01[2] = {0x0UL, MT_MATRIX_A}; if (mti >= MT_N) { int kk; if (mti == MT_N + 1) init_genrand(5489UL); for (kk = 0; kk < MT_N - MT_M; kk++) { y = (mt[kk] & MT_UPPER_MASK) | (mt[kk+1] & MT_LOWER_MASK); mt[kk] = mt[kk+MT_M] ^ (y >> 1) ^ mag01[y&0x1UL]; } for (; kk < MT_N - 1; kk++) { y = (mt[kk] & MT_UPPER_MASK) | (mt[kk+1] & MT_LOWER_MASK); mt[kk] = mt[kk+(MT_M-MT_N)] ^ (y >> 1) ^ mag01[y&0x1UL]; } y = (mt[MT_N-1] & MT_UPPER_MASK) | (mt[0] & MT_LOWER_MASK); mt[MT_N-1] = mt[MT_M-1] ^ (y >> 1) ^ mag01[y&0x1UL]; mti = 0; } y = mt[mti++]; y ^= (y >> 11); y ^= (y << 7) & 0x9d2c5680UL; y ^= (y << 15) & 0xefc60000UL; y ^= (y >> 18); return y; } int is_same(int A[][10], int B[][10]) { int i, j; for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) if (A[i][j] != B[i][j]) return 0; return 1; } int main() { int i, j, N, K, A[10][10], B[10][10]; scanf("%d %d", &N, &K); for (i = 0; i < N; i++) for (j = 0; j < N; j++) scanf("%d", &(B[i][j])); for (i = 0; i < N; i++) for (j = 0; j < N; j++) scanf("%d", &(A[i][j])); int k = 0, ans[1001][2], tmp[10][10], AA[10][10]; for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) AA[i][j] = A[i][j]; while (1) { for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) A[i][j] = AA[i][j]; k = 0; while (is_same(A, B) == 0 && k < 1000) { ans[k][0] = genrand() % 2; ans[k][1] = genrand() % N; if (ans[k][0] == 0) { for (i = 0; i < N; i++) for (j = 0; j < N; j++) tmp[A[ans[k][1]][i]-1][j] = A[i][j]; } else { for (j = 0; j < N; j++) for (i = 0; i < N; i++) tmp[i][A[j][ans[k][1]]-1] = A[i][j]; } for (i = 0; i < N; i++) for (j = 0; j < N; j++) A[i][j] = tmp[i][j]; /* if (ans[k][0] == 0) printf("R "); else printf("C "); printf("%d\n", ans[k][1] + 1); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) printf("%d ", A[i][j]); printf("\n"); } fflush(stdout); */ k++; } if (k < 1000) break; } printf("%d\n", k); for (i = 0; i < k; i++) { if (ans[i][0] == 0) printf("R "); else printf("C "); printf("%d\n", ans[i][1] + 1); } fflush(stdout); return 0; }