fork download
  1. #include <iostream>
  2.  
  3.  
  4. int main()
  5. {
  6. int n, m;
  7.  
  8. std::cin >> n;
  9.  
  10. std::cin >> m;
  11.  
  12. int **Matrix;
  13. Matrix = new int *[n];
  14. for (int i = 0; i < n; i++)
  15. Matrix[i] = new int[m];
  16.  
  17. for (int i = 0; i < n; i++)
  18. for (int j = 0; j < m; j++)
  19. {
  20. std::cin >> Matrix[i][j];
  21. }
  22.  
  23. bool answer = true;
  24. bool bT = false;
  25.  
  26. for (int i = 0; i < n; i++)
  27. {
  28. for (int j = 0; j < m; j++)
  29. {
  30. if (Matrix[i][j] == 1)
  31. {
  32. bT = true;
  33.  
  34. int nT = 1;
  35. int mT = 1;
  36.  
  37. if (i + 1 != n)
  38. {
  39. for (int ii = i + 1; ii < n; ii++)
  40. {
  41. if (Matrix[ii][j] == 1) nT += 1;
  42. else break;
  43. }
  44. }
  45.  
  46. if (j + 1 != m)
  47. {
  48. for (int jj = j + 1; jj < m; jj++)
  49. {
  50. if (Matrix[i][jj] == 1) mT += 1;
  51. else break;
  52. }
  53. }
  54.  
  55. for (int ii = 0, it = i; ii < nT; ii++, it++)
  56. {
  57. for (int jj = 0, jt = j; jj < mT; jj++, jt++)
  58. {
  59. if (Matrix[it][jt] != 1) bT = false;
  60. }
  61. }
  62.  
  63.  
  64. nT = 1;
  65. mT = 1;
  66. if (i != 0)
  67. {
  68. for (int ii = i - 1; ii >= 0; ii--)
  69. {
  70. if (Matrix[ii][j] == 1) nT += 1;
  71. else break;
  72. }
  73. }
  74.  
  75. if (j != 0)
  76. {
  77. for (int jj = j - 1; jj >= 0; jj--)
  78. {
  79. if (Matrix[i][jj] == 1) mT += 1;
  80. else break;
  81. }
  82. }
  83.  
  84. for (int ii = 0, it = i; ii < nT; ii++, it--)
  85. {
  86. for (int jj = 0, jt = j; jj < mT; jj++, jt--)
  87. {
  88. if (Matrix[it][jt] != 1) bT = false;
  89. }
  90. }
  91.  
  92. if (bT == false) answer = bT;
  93.  
  94. }
  95.  
  96. }
  97. }
  98.  
  99. if (answer) std::cout << "Yes";
  100. else std::cout << "No";
  101.  
  102. return 0;
  103. }
Success #stdin #stdout 0s 3460KB
stdin
3 3 
0 0 1
1 1 0
1 1 0
stdout
Yes