#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin >> n >> m;
map<char,map<int,int>> x;
map<char,map<int,int>> y;
set<char> kolory;
map<char,map<int,int>> x2;
map<char,map<int,int>> y2;
char tab[n][m];
//tab[y][x]
///////////ŁADOWANIE DANYCH + PIERWSZE LICZENIE/////////////////////////////////////
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin >> tab[i][j];
kolory.insert(tab[i][j]);
x[tab[i][j]][j]++;
y[tab[i][j]][i]++;
}
}
////////////////////DRUGIE LICZENIE/////////////////////////////
for(char k:kolory){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(tab[i][j]==k){
if(x[k][j]>y[k][i]){
x2[k][j]++;
}else{
y2[k][i]++;
}
}
}
}
}
int mx = max(n,m);
//uwaga wolne
//odp.push_back(make_pair('R', make_pair(i.first + 1, k)));
vector<pair<double,pair<char,pair<int,char>>>> pq;
for(char k:kolory){
for(pair<const int,int> i:x2[k]){
pq.push_back(make_pair(i.second+0.1, make_pair('K', make_pair(i.first+1,k))));
}
for(pair<const int,int> i:y2[k]){
pq.push_back(make_pair(i.second, make_pair('R', make_pair(i.first+1,k))));
}
}
sort(pq.begin(),pq.end());
int sz=pq.size();
cout << sz<< '\n';
for(int i=0;i<sz;i++){
cout << pq[i].second.first <<" "<< pq[i].second.second.first <<" "<< pq[i].second.second.second<<'\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 | #include <bits/stdc++.h> using namespace std; int main() { int n,m; cin >> n >> m; map<char,map<int,int>> x; map<char,map<int,int>> y; set<char> kolory; map<char,map<int,int>> x2; map<char,map<int,int>> y2; char tab[n][m]; //tab[y][x] ///////////ŁADOWANIE DANYCH + PIERWSZE LICZENIE///////////////////////////////////// for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin >> tab[i][j]; kolory.insert(tab[i][j]); x[tab[i][j]][j]++; y[tab[i][j]][i]++; } } ////////////////////DRUGIE LICZENIE///////////////////////////// for(char k:kolory){ for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(tab[i][j]==k){ if(x[k][j]>y[k][i]){ x2[k][j]++; }else{ y2[k][i]++; } } } } } int mx = max(n,m); //uwaga wolne //odp.push_back(make_pair('R', make_pair(i.first + 1, k))); vector<pair<double,pair<char,pair<int,char>>>> pq; for(char k:kolory){ for(pair<const int,int> i:x2[k]){ pq.push_back(make_pair(i.second+0.1, make_pair('K', make_pair(i.first+1,k)))); } for(pair<const int,int> i:y2[k]){ pq.push_back(make_pair(i.second, make_pair('R', make_pair(i.first+1,k)))); } } sort(pq.begin(),pq.end()); int sz=pq.size(); cout << sz<< '\n'; for(int i=0;i<sz;i++){ cout << pq[i].second.first <<" "<< pq[i].second.second.first <<" "<< pq[i].second.second.second<<'\n'; } } |
English