Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<algorithm>
- #include<fstream>
- #define long long long
- #define nln '\n'
- const long N = 1e3 + 10;
- using namespace std;
- // Global variables: n, m, mat
- long n, m, dp[N][N], ans = -1;
- bool mat[N][N];
- fstream f1;
- bool above(long i, long j)
- {
- if (i == 1)
- return 0;
- if (mat[i][j] == mat[i-1][j])
- return 1;
- return 0;
- }
- bool left(long i, long j)
- {
- if (j == 1)
- return 0;
- if (mat[i][j] == mat[i][j-1])
- return 1;
- return 0;
- }
- bool cross(long i, long j)
- {
- if (i == 1 || j == 1)
- return 0;
- if (mat[i][j] == mat[i-1][j-1])
- return 1;
- return 0;
- }
- int main()
- {
- cin >> m >> n;
- for (long i = 1; i <= m; ++i)
- for (long j = 1; j <= n; ++j)
- {
- cin >> mat[i][j];
- dp[i][j] = 1;
- if (cross(i, j) && above(i, j) && left(i, j))
- dp[i][j] = min(min(dp[i-1][j], dp[i-1][j-1]), dp[i][j-1]) + 1;
- if (dp[i][j] > ans)
- ans = dp[i][j];
- }
- cout << ans << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment