1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int H, W;
	cin >> H >> W;
	vector<string> grid(H);
	vector<vector<int>> inRow(H, vector<int>(26));
	vector<vector<int>> inCol(W, vector<int>(26));
	for (int row = 0; row < H; row++) {
		cin >> grid[row];
		for (int col = 0; col < W; col++) {
			++inRow[row][grid[row][col]-'A'];
			++inCol[col][grid[row][col]-'A'];
		}
	}
	vector<pair<char, pair<int,char>>> operations;
	for (int rep = 0; rep < H + W; rep++) {
		for (int row = 0; row < H; row++) {
			int cnt = 0, letter = 0;
			for (int i = 0; i < 26; i++) {
				if (inRow[row][i]) {
					cnt++;
					letter = i;
				}
			}
			
			if (cnt == 1) {
				operations.push_back({'R', {row, 'A'+letter}});
				for (int col = 0; col < W; col++) {
					if(grid[row][col]) {
						--inRow[row][grid[row][col]-'A'];
						--inCol[col][grid[row][col]-'A'];
						grid[row][col] = 0;
					}
				}
			}
		}
		for (int col = 0; col < W; col++) {
			int cnt = 0, letter = 0;
			for (int i = 0; i < 26; i++) {
				if (inCol[col][i]) {
					cnt++;
					letter = i;
				}
			}
			if (cnt == 1) {
				operations.push_back({'K', {col, 'A'+letter}});
				for (int row = 0; row < H; row++) {
					if(grid[row][col]) {
						--inRow[row][grid[row][col]-'A'];
						--inCol[col][grid[row][col]-'A'];
						grid[row][col] = 0;
					}
				}
			}
		}
	}
	cout << operations.size() << "\n";
	reverse(operations.begin(), operations.end());
	for (auto p : operations) {
		cout << p.first << " " << p.second.first + 1 << " " << p.second.second << "\n";
	}
}