Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define rep(i,x,y) for(int i=x;i<y;i++)
- #define repr(i,x,y) for(int i=x;i>=y;i--)
- #define int long long
- #define pb push_back
- #define ff first
- #define ss second
- #define sz(x) ((int)x.size())
- #define all(x) begin(x), end(x)
- #define memo(x,y) memset((x),(y),sizeof((x)))
- #define line cout<<"[At "<<__LINE__<<"]"<<endl;
- using pii = pair<int, int>;
- using vi = vector<int>;
- using vii = vector<pair<int, int>>;
- constexpr int mod = 1e9 + 7, N = 2e5 + 5;
- constexpr long long inf = 1e18;
- constexpr long double eps = 1e-6;
- void Onigiri() {
- int n, m;
- cin >> n >> m;
- int a[n][m];
- rep(i, 0, n)
- rep(j, 0, m)
- cin >> a[i][j];
- int dpl[n][m], dpu[n][m], dp[n][m];
- rep(i, 0, n) {
- rep(j, 0, m) {
- dpl[i][j] = 1;
- if(j != 0 && a[i][j - 1] == a[i][j])
- dpl[i][j] += dpl[i][j - 1];
- }
- }
- rep(i, 0, m) {
- rep(j, 0, n) {
- dpu[j][i] = 1;
- if(j != 0 && a[j - 1][i] == a[j][i])
- dpu[j][i] += dpu[j - 1][i];
- }
- }
- int ans = 0;
- rep(i, 0, n) {
- rep(j, 0, m) {
- dp[i][j] = 1;
- if(i > 0 && j > 0) {
- if(a[i - 1][j - 1] == a[i][j]) {
- int l = dpl[i][j];
- int u = dpu[i][j];
- dp[i][j] = min({dp[i - 1][j - 1] + 1, l, u});
- }
- }
- ans = max(ans, dp[i][j]);
- }
- }
- cout << ans;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- #ifdef Zoro
- freopen("/home/pritish/Competitive/in", "r", stdin);
- freopen("/home/pritish/Competitive/out", "w", stdout);
- #endif
- int t = 1;
- // cin>>t;
- while(t--) {
- Onigiri();
- cout << "\n";
- }
- cerr << "\n" << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement