Advertisement
Guest User

Untitled

a guest
Jan 18th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define rep(i,x,y) for(int i=x;i<y;i++)
  5. #define repr(i,x,y) for(int i=x;i>=y;i--)
  6. #define int long long
  7. #define pb push_back
  8. #define ff first
  9. #define ss second
  10. #define sz(x) ((int)x.size())
  11. #define all(x) begin(x), end(x)
  12. #define memo(x,y) memset((x),(y),sizeof((x)))
  13. #define line cout<<"[At "<<__LINE__<<"]"<<endl;
  14.  
  15. using pii = pair<int, int>;
  16. using vi = vector<int>;
  17. using vii = vector<pair<int, int>>;
  18.  
  19. constexpr int mod = 1e9 + 7, N = 2e5 + 5;
  20. constexpr long long inf = 1e18;
  21. constexpr long double eps = 1e-6;
  22.  
  23.  
  24. void Onigiri() {
  25.   int n, m;
  26.   cin >> n >> m;
  27.   int a[n][m];
  28.   rep(i, 0, n)
  29.     rep(j, 0, m)
  30.       cin >> a[i][j];
  31.  
  32.   int dpl[n][m], dpu[n][m], dp[n][m];
  33.   rep(i, 0, n) {
  34.     rep(j, 0, m) {
  35.       dpl[i][j] = 1;
  36.       if(j != 0 && a[i][j - 1] == a[i][j])
  37.         dpl[i][j] += dpl[i][j - 1];
  38.     }
  39.   }
  40.   rep(i, 0, m) {
  41.     rep(j, 0, n) {
  42.       dpu[j][i] = 1;
  43.       if(j != 0 && a[j - 1][i] == a[j][i])
  44.         dpu[j][i] += dpu[j - 1][i];
  45.     }
  46.   }
  47.   int ans = 0;
  48.   rep(i, 0, n) {
  49.     rep(j, 0, m) {
  50.       dp[i][j] = 1;
  51.       if(i > 0 && j > 0) {
  52.         if(a[i - 1][j - 1] == a[i][j]) {
  53.           int l = dpl[i][j];
  54.           int u = dpu[i][j];
  55.           dp[i][j] = min({dp[i - 1][j - 1] + 1, l, u});
  56.         }
  57.       }
  58.       ans = max(ans, dp[i][j]);
  59.     }
  60.   }
  61.   cout << ans;
  62. }
  63. signed main() {
  64.   ios_base::sync_with_stdio(false);
  65.   cin.tie(NULL);
  66. #ifdef Zoro
  67.   freopen("/home/pritish/Competitive/in", "r", stdin);
  68.   freopen("/home/pritish/Competitive/out", "w", stdout);
  69. #endif
  70.  
  71.   int t = 1;
  72.   // cin>>t;
  73.  
  74.   while(t--) {
  75.     Onigiri();
  76.     cout << "\n";
  77.   }
  78.  
  79.   cerr << "\n" << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
  80.   return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement