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
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <list>

using namespace std;

const int SIZE = 2000;

int main(int argc, char const *argv[])
{
    int n, m;
    string a[SIZE];
    cin >> n >> m;

    for (int i=0; i<n; i++) {
        cin >> a[i];
    }

    list<int> r;
    list<int> k;

    for (int i=0; i<n; i++) {
        r.push_back(i);
    }
    for (int j=0; j<m; j++) {
        k.push_back(j);
    }

    string res[SIZE*2];
    int count = 0;

    list<int>::iterator it, it2;
    char color;

    while (true) {
        for (it=r.begin(); it!=r.end(); ) {
            for (it2=k.begin(), color=a[*it][*it2]; it2!=k.end(); it2++) {
                if (a[*it][*it2] != color) {
                    color = ' ';
                    break;
                }
            }
            if (color == ' ') {
                it++;
            } else {
                res[count] = "R " + to_string(*it + 1) + " " + color;
                count++;
                it = r.erase(it);
            }
        }
        if (r.empty()) {
            break;
        }

        for (it=k.begin(); it!=k.end(); ) {
            char c = ' ';
            for (it2=r.begin(), color=a[*it2][*it]; it2!=r.end(); it2++) {
                if (a[*it2][*it] != color) {
                    color = ' ';
                    break;
                }
            }
            if (color == ' ') {
                it++;
            } else {
                res[count] = "K " + to_string(*it + 1) + " " + color;
                count++;
                it = r.erase(it);
            }
        }
        if (k.empty()) {
            break;
        }
    }

    cout << count << endl;
    for (int i=count-1; i>=0; i--) {
        cout << res[i] << endl;
    }

    return 0;
}