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
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int n, m;
std::vector<std::vector<char>> board;
//. = blank
vector<tuple<bool,int,char>> moves;
bool actual_r;int actual_nr;char actual_col;
bool good = true;
// true = R false = K
//Z = blue , A = Zółty , P = zielony

int main() {
    cin >> n >> m;
    board =  vector<vector<char>>(n, std::vector<char>(m));

    cin.ignore();
    
    std::string line;
    for (int i = 0; i < n; i++) {
        std::getline(std::cin, line);
        for (int j = 0; j < m; j++) {
            board[i][j] = line[j];
        }
    }

    for(int a = 0; a < n+m; a++){
        actual_r = true;
        for(int i = 0;i < n;i++){
            good = false;
            actual_col = '.';
            actual_nr = i;
            for(int j = 0;j < m;j++){
                if (actual_col == '.' && board[i][j] != '.') {
                    actual_col = board[i][j];
                    good = true;
                }else if (actual_col == board[i][j] || board[i][j] == '.' ) {
                }
                else{
                    good = false;
                    break;
                }
            }
            if (good) {
                moves.push_back(make_tuple(actual_r,actual_nr,actual_col));
                for (int j = 0; j < m; j++) {
                    board[i][j] = '.';
                }
            }
        }
        actual_r = false;
        for(int j = 0;j < m;j++){
            good = false;
            actual_col = '.';
            actual_nr = j;
            for(int i = 0;i < n;i++){
                if (actual_col == '.' && board[i][j] != '.') {
                    actual_col = board[i][j];
                    good = true;
                } else if (actual_col == board[i][j] || board[i][j] == '.' ) {
                }
                else{
                    good = false;
                    break;
                }
            }
            if (good) {
                moves.push_back(make_tuple(actual_r,actual_nr,actual_col));
                for (int i = 0; i < n; i++) {
                    board[i][j] = '.';
                }
            }
        }
    }

    cout << moves.size() << endl;
    for (int i = moves.size()-1; i >= 0; i--) {
        if (get<0>(moves[i])) {
            cout << "R " << get<1>(moves[i])+1<< " " << get<2>(moves[i]) << endl;            
        }
        else {
            cout << "K " << get<1>(moves[i])+1<< " " << get<2>(moves[i]) << endl;
        }
    }
    

    return 0;
}