fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 1000;
  5.  
  6. bool is_square(int upLeftX, int upLeftY, int k, short int mt[MAX_SIZE][MAX_SIZE]) {
  7. int sameDigit = mt[upLeftX][upLeftY];
  8. for (int s = 1; s <= k; ++s) {
  9. bool equals = mt[upLeftX][upLeftY + s] != sameDigit || mt[upLeftX + k][upLeftY + s] != sameDigit;
  10. if (equals || mt[upLeftX + s][upLeftY] != sameDigit || mt[upLeftX + s][upLeftY + k] != sameDigit) {
  11. return false;
  12. }
  13. }
  14. return true;
  15. }
  16. int biggestSquare(int sizeX, int sizeY, short int mt[MAX_SIZE][MAX_SIZE]) {
  17. int max = 1;
  18. for (int i = 1; i <= sizeX - max; ++i) {
  19. for (int j = 1; j <= sizeY - max; ++j) {
  20. for (int k = max; i + k <= sizeX && j + k <= sizeY; ++k) {
  21. if (is_square(i, j, k, mt)) {
  22. max = k + 1;
  23. }
  24. }
  25. }
  26. }
  27. return max;
  28. }
  29.  
  30. int main() {
  31. int sizeX, sizeY;
  32. short int mt[MAX_SIZE][MAX_SIZE];
  33. cin >> sizeX >> sizeY;
  34. for (int i = 1; i <= sizeX; ++i) {
  35. for(int j = 1; j <= sizeY; ++j) {
  36. cin >> mt[i][j];
  37. }
  38. }
  39. cout << biggestSquare(sizeX, sizeY, mt);
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 5452KB
stdin
11 10
6	3	4	0	9	7	3	6	5	8
6	9	4	3	2	8	2	6	8	7
4	5	5	5	8	1	0	7	1	0
0	1	0	0	0	0	0	9	7	9
8	3	0	4	0	5	0	7	2	0
7	9	0	0	0	6	0	5	1	5
2	4	0	4	8	9	0	7	2	8
4	2	0	0	0	0	0	5	5	6
8	2	1	6	7	7	8	6	6	8
2	3	4	1	8	0	6	5	8	0
8	7	7	2	3	0	3	2	5	8
stdout
5