fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <fstream>
  7. #include <cstdlib>
  8.  
  9. #define rep( i, l, r ) for (int i = l; i <= r; i++)
  10. #define down( i, l, r ) for (int i = l; i >= r; i--)
  11. #define MS 2009
  12. #define MAX 1073741823
  13.  
  14. using namespace std;
  15.  
  16. int num[MS][MS], n, m, l[MS][MS], r[MS][MS], h[MS][MS], ans1, ans2, a;
  17.  
  18. int main()
  19. {
  20. scanf("%d%d", &n, &m);
  21. rep(i, 1, n) rep(j, 1, m) scanf("%d", &num[i][j]);
  22. rep(j, 1, m) h[1][j] = 1;
  23. rep(i, 1, n) { l[i][1] = 1; r[i][m] = 1; }
  24. rep(i, 2, n) rep(j, 1, m) if (num[i][j] != num[i-1][j]) h[i][j] = h[i-1][j] + 1; else h[i][j] = 1;
  25. rep(i, 1, n) rep(j, 2, m) if (num[i][j] != num[i][j-1]) l[i][j] = l[i][j-1] + 1; else l[i][j] = 1;
  26. rep(i, 1, n) down(j, m-1, 1) if (num[i][j] != num[i][j+1]) r[i][j] = r[i][j+1] + 1; else r[i][j] = 1;
  27. ans1 = ans2 = 1;
  28. rep(i, 1, n) rep(j, 1, m)
  29. {
  30. if (h[i][j] == 1) ans2 = max(ans2, l[i][j]+r[i][j]-1); else
  31. {
  32. l[i][j] = min(l[i][j], l[i-1][j]);
  33. r[i][j] = min(r[i][j], r[i-1][j]);
  34. a = min(l[i][j]+r[i][j]-1, h[i][j]); ans1 = max(ans1, a);
  35. ans2 = max(ans2, (l[i][j]+r[i][j]-1)*h[i][j]);
  36. }
  37. }
  38. printf("%d\n%d\n", ans1*ans1, ans2);
  39. return 0;
  40. }
Success #stdin #stdout 0s 66432KB
stdin
3 3
1 0 1
0 1 0
1 0 0
stdout
4
6