Iamtui1010

qbsquare

Nov 10th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<fstream>
  5.  
  6. #define long long long
  7. #define nln '\n'
  8.  
  9. const long N = 1e3 + 10;
  10.  
  11. using namespace std;
  12.  
  13. // Global variables: n, m, mat
  14.  
  15. long n, m, dp[N][N], ans = -1;
  16. bool mat[N][N];
  17. fstream f1;
  18.  
  19. bool above(long i, long j)
  20. {
  21.     if (i == 1)
  22.         return 0;
  23.     if (mat[i][j] == mat[i-1][j])
  24.         return 1;
  25.     return 0;
  26. }
  27.  
  28. bool left(long i, long j)
  29. {
  30.     if (j == 1)
  31.         return 0;
  32.     if (mat[i][j] == mat[i][j-1])
  33.         return 1;
  34.     return 0;
  35. }
  36.  
  37. bool cross(long i, long j)
  38. {
  39.     if (i == 1 || j == 1)
  40.         return 0;
  41.     if (mat[i][j] == mat[i-1][j-1])
  42.         return 1;
  43.     return 0;
  44. }
  45.  
  46. int main()
  47. {
  48.     cin >> m >> n;
  49.     for (long i = 1; i <= m; ++i)
  50.         for (long j = 1; j <= n; ++j)
  51.         {
  52.             cin >> mat[i][j];
  53.             dp[i][j] = 1;
  54.             if (cross(i, j) && above(i, j) && left(i, j))
  55.                 dp[i][j] = min(min(dp[i-1][j], dp[i-1][j-1]), dp[i][j-1]) + 1;
  56.             if (dp[i][j] > ans)
  57.                 ans = dp[i][j];
  58.         }
  59.     cout << ans << nln;
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment