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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int n,m;
int zostalo;

vector<bool> czyw, czyk;
stack<vector<int>> ruchy;
void czyscWier(){
    for (int i = 0; i < n; ++i) {
        if(czyw[i]) continue;
        char c ='.';
        bool git = true;

        for (int j = 0; j < m; ++j) { //czy jednolite lub z .
            if(v[i][j] !='.' && c == '.') c = v[i][j];
            if(v[i][j] != c && v[i][j]!='.') {
                git = false;
                break;
            }
        }

        if(git) {
            czyw[i] = true;
            ruchy.push({1, i, c});

            for (int j = 0; j < m; ++j) { //czyszcze
                if(v[i][j] != '.') zostalo--;
                v[i][j] = '.';
            }
        }
    }
}

void czyscKol(){
    for (int i = 0; i < m; ++i) {
        if(czyk[i]) continue;
        char c = '.';
        bool git = true;

        for (int j = 0; j < n; ++j) { //czy jednolite lub z .
            if(v[j][i] !='.' && c == '.') c = v[j][i];
            if(v[j][i] != c && v[j][i]!='.') {
                git = false;
                break;
            }
        }

        if(git) {
            czyk[i] = true;
            if(c=='.') continue;
            ruchy.push({0, i, c});

            for (int j = 0; j < n; ++j) { //czyszcze
                if(v[j][i] != '.') zostalo--;
                v[j][i] = '.';
            }
        }
    }
}

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin>>n>>m;

    czyw = vector<bool>(n);
    czyk = vector<bool>(m);

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

    zostalo = n*m;
    bool terw = true;
    while(zostalo > 0) {
        if(terw) czyscWier();
        else czyscKol();
        terw = !terw;
    }

    cout<<ruchy.size()<<"\n";
    while(!ruchy.empty()) {
        vector<int> r = ruchy.top(); ruchy.pop();
        cout<<(r[0]?"R":"K")<<" "<<(r[1]+1)<<" "<<(char)r[2]<<"\n";
    }
}

/*
 5 5
AAPAA
APPAA
AAPAA
AAPAA
APPPA

 */