fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define sz(a) int((a).size())
  4. #define fr(i,n) for(int i=0;i<n;i++)
  5. #define frr(i,n) for(int i=1;i<n;i++)
  6. #define rf(i,n) for(int i=1;i<=n;i++)
  7. #define pb push_back
  8. #define all(c) (c).begin(),(c).end()
  9. #define tr(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
  10. #define present(c,x) ((c).find(x) != (c).end())
  11. #define cpresent(c,x) (find(all(c),x) != (c).end())
  12. #define MAX INT_MAX
  13. using namespace std;
  14. int r[100001],c[100001];
  15. int main()
  16. {
  17. ios_base::sync_with_stdio(false);
  18. cin.tie(NULL);
  19. int t;
  20. cin>>t;
  21. while(t--)
  22. {
  23. int n,m;
  24. cin>>n>>m;
  25. string s[n];
  26. fr(j,n)
  27. cin>>s[j];
  28. bool b[n][m],p=0;
  29. fr(i,n)
  30. fr(j,m)
  31. {
  32.  
  33. b[i][j]=(int)s[i][j]-'0';
  34. if(b[i][j]==1)
  35. {
  36. p=1;
  37. r[i]=1;
  38. c[j]=1;
  39. }
  40. }
  41. if(p==0)
  42. {
  43. fr(i,n)
  44. {
  45. fr(j,m)
  46. cout<<-1<<" ";
  47. cout<<endl;
  48. }
  49. }
  50. else
  51. {
  52. fr(i,n)
  53. {
  54. fr(j,m)
  55. {
  56. if(b[i][j]==1)
  57. cout<<0<<" ";
  58. else
  59. if(r[i]==1 || c[j]==1)
  60. cout<<1<<" ";
  61. else
  62. cout<<2<<" ";
  63. }
  64. cout<<endl;
  65. }
  66. }
  67. }
  68. return 0;
  69. }
Success #stdin #stdout 0s 4328KB
stdin
1
3 3
010
000
001
stdout
1 0 1 
2 1 1 
1 1 0