fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. int a[10005][10005],cnt[10005][10005];
  5. signed main(){
  6. // freopen("FLATLAND.INP", "r", stdin);
  7. // freopen("FLATLAND.OUT", "w", stdout);
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL);
  10. int n,m;
  11. cin >> n >> m;
  12. for(int i = 0; i < n; ++i){
  13. for(int j = 0; j < m; ++j){
  14. cin >> a[i][j];
  15. }
  16. }
  17. for(int i = 0;i < n;++i){
  18. for(int j = 0; j < m; j++){
  19. cnt[i][j] = 1;
  20. int x = j+1;
  21. while(a[i][j] == a[i][x] && x < m){
  22. cnt[i][j]++;
  23. ++x;
  24. }
  25. }
  26. }
  27. int maxx= 0;
  28. for(int i = 0; i < n-1; ++i){
  29. for(int j = 0; j < m; ++j){
  30. int h = 1,w = cnt[i][j];
  31. int r = i+1;
  32. while(a[i][j] == a[r][j] && r < n){
  33. ++h;
  34. w = min(cnt[r][j],w);
  35. ++r;
  36. }
  37. maxx = max(maxx,2*(h+w));
  38. }
  39. }
  40. cout << maxx;
  41. }
Success #stdin #stdout 0.01s 5576KB
stdin
6 8 
0 0 1 0 0 0 0 0 
1 0 1 0 1 1 0 0 
1 0 1 0 1 1 1 1 
1 0 1 0 1 1 1 1 
1 0 1 0 1 1 1 1 
1 1 1 1 1 1 1 1 
stdout
16