#include<bits/stdc++.h>
using namespace std;
struct typ{
char r;
int numer;
char kolor;
};
vector<bool> odw_rows(2007);
vector<bool> odw_cols(2007);
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.in", "r", stdin);
int n,m;
cin>>n>>m;
vector<unordered_map<char,int>> columns(m);
vector<unordered_map<char,int>> rows(n);
char a;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cin>>a;
rows[i][a]++;
columns[j][a]++;
}
}
vector<typ> wyn;
int r=n;
int c=m;
while(1){
bool wart=0;
int numer;
char kolor;
//szukaj w wierszach
for(int i=0; i<n; i++){
if(!odw_rows[i]){
//kandydat
for(auto e:rows[i]){
if(e.second==c and c>0){
numer=i;
kolor=e.first;
wart=true;
odw_rows[numer]=1;
r--;
wyn.push_back({'R',numer,kolor});
for(int i=0; i<m; i++){
columns[i][kolor]--;
}
}
}
}
}
for(int i=0; i<m; i++){
if(!odw_cols[i]){
//kandydat
for(auto e:columns[i]){
if(e.second==r and r>0){
numer=i;
kolor=e.first;
wart=true;
odw_cols[numer]=1;
c--;
wyn.push_back({'K',numer,kolor});
for(int i=0; i<n; i++){
rows[i][kolor]--;
}
}
}
}
}
if(!wart){
break;
//koniec
}
//wymaz ten wiersz
if(r==0 and c==0){
break;
}
}
reverse(wyn.begin(),wyn.end());
cout<<wyn.size()<<"\n";
for(int i=0; i<wyn.size(); i++){
cout<<wyn[i].r<<" "<<wyn[i].numer+1<<" "<<wyn[i].kolor<<"\n";
}
}
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; struct typ{ char r; int numer; char kolor; }; vector<bool> odw_rows(2007); vector<bool> odw_cols(2007); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.in", "r", stdin); int n,m; cin>>n>>m; vector<unordered_map<char,int>> columns(m); vector<unordered_map<char,int>> rows(n); char a; for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ cin>>a; rows[i][a]++; columns[j][a]++; } } vector<typ> wyn; int r=n; int c=m; while(1){ bool wart=0; int numer; char kolor; //szukaj w wierszach for(int i=0; i<n; i++){ if(!odw_rows[i]){ //kandydat for(auto e:rows[i]){ if(e.second==c and c>0){ numer=i; kolor=e.first; wart=true; odw_rows[numer]=1; r--; wyn.push_back({'R',numer,kolor}); for(int i=0; i<m; i++){ columns[i][kolor]--; } } } } } for(int i=0; i<m; i++){ if(!odw_cols[i]){ //kandydat for(auto e:columns[i]){ if(e.second==r and r>0){ numer=i; kolor=e.first; wart=true; odw_cols[numer]=1; c--; wyn.push_back({'K',numer,kolor}); for(int i=0; i<n; i++){ rows[i][kolor]--; } } } } } if(!wart){ break; //koniec } //wymaz ten wiersz if(r==0 and c==0){ break; } } reverse(wyn.begin(),wyn.end()); cout<<wyn.size()<<"\n"; for(int i=0; i<wyn.size(); i++){ cout<<wyn[i].r<<" "<<wyn[i].numer+1<<" "<<wyn[i].kolor<<"\n"; } } |
English