//泥の分際で私だけの大切を奪おうだなん #include<bits/stdc++.h> using namespace std; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } char op[4003],col[4003]; int id[4003],cnt; char s[4003][4003]; bool vr[4003],vc[4003]; int ar[4003][26],ac[4003][26]; int cr[4003],cc[4003]; signed main() { int n=read(),m=read(); for(int i=1; i<=n; ++i) scanf("%s",s[i]+1); for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) cr[i]+=(!ar[i][s[i][j]-'A']++), cc[j]+=(!ac[j][s[i][j]-'A']++); for(int i=1; i<=n+m; ++i) { for(int j=1; j<=n; ++j) if(!vr[j]&&cr[j]<=1) { char tgt='?'; for(int k=1; k<=m; ++k) if(isupper(s[j][k])&&tgt=='?') tgt=s[j][k]; if(tgt!='?') op[++cnt]='R',id[cnt]=j,col[cnt]=tgt; for(int k=1; k<=m; ++k) if(s[j][k]!='?') cr[j]-=(!--ar[j][s[j][k]-'A']), cc[k]-=(!--ac[k][s[j][k]-'A']), s[j][k]='?'; vr[j]=1; } for(int j=1; j<=m; ++j) if(!vc[j]&&cc[j]<=1) { char tgt='?'; for(int k=1; k<=n; ++k) if(isupper(s[k][j])&&tgt=='?') tgt=s[k][j]; if(tgt!='?') op[++cnt]='K',id[cnt]=j,col[cnt]=tgt; for(int k=1; k<=n; ++k) if(s[k][j]!='?') cr[k]-=(!--ar[k][s[k][j]-'A']), cc[j]-=(!--ac[j][s[k][j]-'A']), s[k][j]='?'; vc[j]=1; } } printf("%d\n",cnt); while(cnt) printf("%c %d %c\n",op[cnt],id[cnt],col[cnt]),--cnt; 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 | //泥の分際で私だけの大切を奪おうだなん #include<bits/stdc++.h> using namespace std; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } char op[4003],col[4003]; int id[4003],cnt; char s[4003][4003]; bool vr[4003],vc[4003]; int ar[4003][26],ac[4003][26]; int cr[4003],cc[4003]; signed main() { int n=read(),m=read(); for(int i=1; i<=n; ++i) scanf("%s",s[i]+1); for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) cr[i]+=(!ar[i][s[i][j]-'A']++), cc[j]+=(!ac[j][s[i][j]-'A']++); for(int i=1; i<=n+m; ++i) { for(int j=1; j<=n; ++j) if(!vr[j]&&cr[j]<=1) { char tgt='?'; for(int k=1; k<=m; ++k) if(isupper(s[j][k])&&tgt=='?') tgt=s[j][k]; if(tgt!='?') op[++cnt]='R',id[cnt]=j,col[cnt]=tgt; for(int k=1; k<=m; ++k) if(s[j][k]!='?') cr[j]-=(!--ar[j][s[j][k]-'A']), cc[k]-=(!--ac[k][s[j][k]-'A']), s[j][k]='?'; vr[j]=1; } for(int j=1; j<=m; ++j) if(!vc[j]&&cc[j]<=1) { char tgt='?'; for(int k=1; k<=n; ++k) if(isupper(s[k][j])&&tgt=='?') tgt=s[k][j]; if(tgt!='?') op[++cnt]='K',id[cnt]=j,col[cnt]=tgt; for(int k=1; k<=n; ++k) if(s[k][j]!='?') cr[k]-=(!--ar[k][s[k][j]-'A']), cc[j]-=(!--ac[j][s[k][j]-'A']), s[k][j]='?'; vc[j]=1; } } printf("%d\n",cnt); while(cnt) printf("%c %d %c\n",op[cnt],id[cnt],col[cnt]),--cnt; return 0; } |