#include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long using namespace std; const int N=2e3+5; int n,m; string s[N]; int vx[N],vy[N],R[N][26],C[N][26]; vector<tuple<char,int,char>>ans; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n>>m; for(int i=0;i<n;++i)cin>>s[i]; for(int i=0;i<n;++i) for(int j=0;j<m;++j) ++R[i][s[i][j]-'A'], ++C[j][s[i][j]-'A']; for(int x=n,y=m;x&&y;){ bool ok=0; for(int c=0;!ok&&c<26;++c) for(int i=0;i<n;++i) if(!vx[i]&&R[i][c]==y){ ok=1,--x,vx[i]=1,ans.emplace_back('R',i,'A'+c); for(int j=0;j<m;++j)if(!vy[j])--C[j][s[i][j]-'A']; } for(int c=0;!ok&&c<26;++c) for(int j=0;j<m;++j) if(!vy[j]&&C[j][c]==x){ ok=1,--y,vy[j]=1,ans.emplace_back('K',j,'A'+c); for(int i=0;i<n;++i)if(!vx[i])--R[i][s[i][j]-'A']; } } reverse(ans.begin(),ans.end()); cout<<ans.size()<<'\n'; for(auto [x,y,z]:ans)cout<<x<<' '<<y+1<<' '<<z<<'\n'; 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 | #include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long using namespace std; const int N=2e3+5; int n,m; string s[N]; int vx[N],vy[N],R[N][26],C[N][26]; vector<tuple<char,int,char>>ans; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n>>m; for(int i=0;i<n;++i)cin>>s[i]; for(int i=0;i<n;++i) for(int j=0;j<m;++j) ++R[i][s[i][j]-'A'], ++C[j][s[i][j]-'A']; for(int x=n,y=m;x&&y;){ bool ok=0; for(int c=0;!ok&&c<26;++c) for(int i=0;i<n;++i) if(!vx[i]&&R[i][c]==y){ ok=1,--x,vx[i]=1,ans.emplace_back('R',i,'A'+c); for(int j=0;j<m;++j)if(!vy[j])--C[j][s[i][j]-'A']; } for(int c=0;!ok&&c<26;++c) for(int j=0;j<m;++j) if(!vy[j]&&C[j][c]==x){ ok=1,--y,vy[j]=1,ans.emplace_back('K',j,'A'+c); for(int i=0;i<n;++i)if(!vx[i])--R[i][s[i][j]-'A']; } } reverse(ans.begin(),ans.end()); cout<<ans.size()<<'\n'; for(auto [x,y,z]:ans)cout<<x<<' '<<y+1<<' '<<z<<'\n'; return 0; } /* */ |