fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. bool BreakRow (int **chocolate, int n, int m){
  6. for (int i = 0; i < n - 1; i++){
  7. bool okRow = true;
  8. for (int j = 0; j < m; j++){
  9. if(chocolate[i][j] == chocolate [i + 1][j]){okRow = false;break;}
  10. }
  11. if (okRow) return true;
  12. }
  13. return false;
  14. }
  15. bool BreakColumn (int **chocolate, int n, int m){
  16. for (int i = 0; i < m - 1; i++){
  17. bool okColumn = true;
  18. for (int j = 0; j < n; j++){
  19. if(chocolate[j][i] == chocolate[j][i + 1]){okColumn = false;break;}
  20. }
  21. if (okColumn) return true;
  22. }
  23. return false;
  24. }
  25.  
  26. int check (int **chocolate, int n, int m){
  27. if ( BreakRow(chocolate, n, m) || BreakColumn (chocolate, n, m)) cout<<"Yes";
  28. else cout<<"No";
  29. }
  30.  
  31. int main() {
  32. int n, m;
  33. cin >> n >> m;
  34. int **chocolate = new int* [n];
  35. for(int i = 0; i < n; ++i){
  36. chocolate[i] = new int[m];
  37. }
  38. for( int i = 0; i < n; i++){
  39. for(int j = 0; j < m; j++){
  40. cin >> chocolate [i][j];
  41. }
  42. }
  43. check(chocolate, n, m);
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 4388KB
stdin
5 6
1 2 2 3 3 4
1 5 6 7 7 4
8 5 6 9 10 10
8 11 11 9 12 13
14 14 15 15 12 13
stdout
No