fork download
  1. // Source: https://u...content-available-to-author-only...o.guide/general/io
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int t;
  9. cin >> t;
  10. while (t--)
  11. {
  12. int n, m;
  13. cin >> n >> m;
  14. int a[n + 1][m + 1];
  15. int ne[n + 1][m + 1];
  16. for (int i = 1; i <= n; i++)
  17. {
  18. for (int j = 1; j <= m; j++)
  19. {
  20. char x;
  21. cin >> x;
  22. a[i][j] = x - '0';
  23. ne[i][j] = x - '0';
  24. }
  25. }
  26.  
  27. int c = 0;
  28. for (int i = 1; i <= n; i++)
  29. {
  30. for (int j = 1; j <= m; j++)
  31. {
  32. if (a[i][j] == 1)
  33. {
  34. c = -1;
  35. while (i + (++c) <= n && j + (c) <= m)
  36. ne[i + c][j + c] = 1;
  37.  
  38. c = -1;
  39. while (i - (++c) >= 1 && j - (c) >= 1)
  40. ne[i - c][j - c] = 1;
  41.  
  42. c = -1;
  43. while (i - (++c) >= 1 && j + (c) <= m)
  44. ne[i - c][j + c] = 1;
  45.  
  46. c = -1;
  47. while (i + (++c) <= n && j - (c) >= 1)
  48. ne[i + c][j - c] = 1;
  49. }
  50. }
  51. }
  52.  
  53. for (int i = 1; i <= n; i++)
  54. {
  55. for (int j = 1; j <= m; j++)
  56. {
  57. cout << ne[i][j];
  58. }
  59. cout << endl;
  60. }
  61. }
  62. }
  63.  
Success #stdin #stdout 0.01s 5280KB
stdin
2
3 3
010
010
000
1 2
01
stdout
111
111
101
01