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
67
68
69
70
71
#include <bits/stdc++.h>

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,x;
    cin >> n >> m;
    int  n1=n,m1=m;
    char a,b;
    vector<vector<int>>k(m,vector<int>(26, 0));
    vector<vector<int>>r(n,vector<int>(26, 0));
    vector<vector<int>>v(n, vector<int>(m));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
           cin >> a;
           x = (int)a;
           x -= 65;
           v[i][j] = x;
           k[j][x]++;
           r[i][x]++;
        } 
    }
    stack<pair<char, pair<int, int>>>odp;

    while (m1 > 0 and n1 > 0){
        for (int i = 0; i < m; i++){
            if(m1 <= 0)break;
            for (int j = 0; j < 26; j++){
                if(k[i][j] == n1){
                    k[i][j] = 0;
                    odp.push(make_pair('K', make_pair(i+1,j)));
                    m1--;
                    for (int l = 0; l < n; l++){
                        r[l][j]--;
                    }
                    break;
                }
                else if(k[i][j] > 0)break;
            } 
        }
        for (int i = 0; i < n; i++){
            if(n1 <= 0)break;
            for (int j = 0; j < 26; j++){
                if(r[i][j] == m1){
                    odp.push(make_pair('R',make_pair(i+1,j)));
                    n1--;
                    for (int l = 0; l < m; l++){
                        k[l][j]--;
                    }
                    break;
                }
                else if(r[i][j] > 0)break;
            } 
        }
    }
    cout << odp.size() << endl;
    while (odp.size() > 0){
        pair<char,pair<int, int>>p;
        p = odp.top();
        odp.pop();
        x = p.second.second;
        x += 65;
        a = (char)x;
        b = p.first;
        x = p.second.first;
        cout << b << " " << x << " " << a << endl;
    } 
}