#include <iostream> #include <vector> #include <map> #include <algorithm> #include <queue> int paints[4007][30]; using namespace std; int n, m; const int letters = 26; vector<pair<int, int> >V2; void paint(int a, int b){ V2.push_back({a, b}); paints[a][letters]=0; if(a>=n){ for(int i=n;i<n+n;i++){ if(paints[i-n][letters] == 0){ continue; } paints[i-n][b]--; paints[i-n][letters]--; } } else{ for(int i=0;i<m;i++){ if(paints[i+n][letters] == 0){ continue; } paints[i+n][b]--; paints[i+n][letters]--; } } for(int i=0;i<m;i++){ for(int j=0;j<letters;j++){ if(paints[i+n][j] == paints[i+n][letters]&&paints[i+n][letters]!=0){ paint(i+n, j); } } } for(int i=n;i<n+n;i++){ for(int j=0;j<letters;j++){ if(paints[i-n][j] == paints[i-n][letters]&&paints[i-n][letters]!=0){ paint(i-n, j); } } } } int main() { cin >> n >> m; char c; pair<int, int> P; bool flag = 1; for (int i = 0; i < n; ++i) { for(int j=0;j<m;j++){ cin>>c; c = (int)c - (int)'A'; paints[i][c]++; paints[j+n][c]++; if(paints[i][c] == m && flag){ P = {i, c}; } if(paints[j+n][c] == n && flag){ P = {j+n, c}; flag = false; } paints[i][letters] = m; paints[j+n][letters]= n; } } paint(P.first, P.second); cout<<V2.size()<<endl; for(int i=V2.size()-1;i>=0;i--){ if(V2[i].first<n){ cout<< "R "<< V2[i].first + 1 <<" "<<char('A'+V2[i].second)<<endl; } else{ cout<< "K "<< V2[i].first + 1 - n <<" "<<char('A'+V2[i].second)<<endl; } } return 0; }
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 | #include <iostream> #include <vector> #include <map> #include <algorithm> #include <queue> int paints[4007][30]; using namespace std; int n, m; const int letters = 26; vector<pair<int, int> >V2; void paint(int a, int b){ V2.push_back({a, b}); paints[a][letters]=0; if(a>=n){ for(int i=n;i<n+n;i++){ if(paints[i-n][letters] == 0){ continue; } paints[i-n][b]--; paints[i-n][letters]--; } } else{ for(int i=0;i<m;i++){ if(paints[i+n][letters] == 0){ continue; } paints[i+n][b]--; paints[i+n][letters]--; } } for(int i=0;i<m;i++){ for(int j=0;j<letters;j++){ if(paints[i+n][j] == paints[i+n][letters]&&paints[i+n][letters]!=0){ paint(i+n, j); } } } for(int i=n;i<n+n;i++){ for(int j=0;j<letters;j++){ if(paints[i-n][j] == paints[i-n][letters]&&paints[i-n][letters]!=0){ paint(i-n, j); } } } } int main() { cin >> n >> m; char c; pair<int, int> P; bool flag = 1; for (int i = 0; i < n; ++i) { for(int j=0;j<m;j++){ cin>>c; c = (int)c - (int)'A'; paints[i][c]++; paints[j+n][c]++; if(paints[i][c] == m && flag){ P = {i, c}; } if(paints[j+n][c] == n && flag){ P = {j+n, c}; flag = false; } paints[i][letters] = m; paints[j+n][letters]= n; } } paint(P.first, P.second); cout<<V2.size()<<endl; for(int i=V2.size()-1;i>=0;i--){ if(V2[i].first<n){ cout<< "R "<< V2[i].first + 1 <<" "<<char('A'+V2[i].second)<<endl; } else{ cout<< "K "<< V2[i].first + 1 - n <<" "<<char('A'+V2[i].second)<<endl; } } return 0; } |