#include <iostream> #include <vector> using namespace std; struct trzy { char kr; int nr; char k; }; int n, m, rz[2001][27], kol[2001][27], ilr, ilk; char in; vector <int> a; vector <trzy> res; vector <int> vec; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; ilr = n; ilk = m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin>>in; rz[i][in - 65]++; kol[j][in - 65]++; } } while(ilk != 0 || ilr != 0) { for(int i = 1; i <= n; i++) { if(rz[i][26] == 0) { for(int j = 0; j < vec.size(); j++) { rz[i][vec[j]]--; } } } vec.clear(); for(int i = 1; i <= n; i++) { if(rz[i][26] == 0) { for(int j = 0; j < 26; j++) { if(rz[i][j] == ilk) { vec.push_back(j); rz[i][26] = -1; res.push_back({'R', i, (char(j + 65))}); ilr--; break; } } } } for(int i = 1; i <= m; i++) { if(kol[i][26] == 0) { for(int j = 0; j < vec.size(); j++) { kol[i][vec[j]]--; } } } vec.clear(); for(int i = 1; i <= m; i++) { if(kol[i][26] == 0) { for(int j = 0; j < 26; j++) { if(kol[i][j] == ilr) { vec.push_back(j); kol[i][26] = -1; res.push_back({'K', i, (char(j + 65))}); ilk--; break; } } } } } cout<<res.size()<<'\n'; for(int i = res.size() - 1; i >= 0; i--) { cout<<res[i].kr<<' '<<res[i].nr<<' '<<res[i].k<<'\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 | #include <iostream> #include <vector> using namespace std; struct trzy { char kr; int nr; char k; }; int n, m, rz[2001][27], kol[2001][27], ilr, ilk; char in; vector <int> a; vector <trzy> res; vector <int> vec; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; ilr = n; ilk = m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin>>in; rz[i][in - 65]++; kol[j][in - 65]++; } } while(ilk != 0 || ilr != 0) { for(int i = 1; i <= n; i++) { if(rz[i][26] == 0) { for(int j = 0; j < vec.size(); j++) { rz[i][vec[j]]--; } } } vec.clear(); for(int i = 1; i <= n; i++) { if(rz[i][26] == 0) { for(int j = 0; j < 26; j++) { if(rz[i][j] == ilk) { vec.push_back(j); rz[i][26] = -1; res.push_back({'R', i, (char(j + 65))}); ilr--; break; } } } } for(int i = 1; i <= m; i++) { if(kol[i][26] == 0) { for(int j = 0; j < vec.size(); j++) { kol[i][vec[j]]--; } } } vec.clear(); for(int i = 1; i <= m; i++) { if(kol[i][26] == 0) { for(int j = 0; j < 26; j++) { if(kol[i][j] == ilr) { vec.push_back(j); kol[i][26] = -1; res.push_back({'K', i, (char(j + 65))}); ilk--; break; } } } } } cout<<res.size()<<'\n'; for(int i = res.size() - 1; i >= 0; i--) { cout<<res[i].kr<<' '<<res[i].nr<<' '<<res[i].k<<'\n'; } } |