fork(3) download
  1. #include <bits/stdc++.h>
  2. #define fst first
  3. #define snd second
  4. #define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
  5. #define pb push_back
  6. #define ALL(s) s.begin(),s.end()
  7. #define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  8. #define SZ(s) int(s.size())
  9. using namespace std;
  10. typedef long long ll;
  11. typedef pair<int,int> ii;
  12.  
  13. int dp[1010][1010];
  14. string s[1010];
  15.  
  16. int main(){FIN;
  17. int n,m,ans=0; cin>>n>>m;
  18. fore(i,0,n) cin>>s[i];
  19. fore(i,0,n) fore(j,0,m){
  20. bool up=i&&j&&s[i-1][j]==s[i-1][j-1];
  21. bool dw=j&&s[i][j-1]==s[i][j];
  22. if(up&&dw) dp[i][j]=min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]})+1;
  23. else dp[i][j]=1;
  24. ans=max(ans,dp[i][j]);
  25. }
  26. cout << ans*ans << "\n";
  27. }
Success #stdin #stdout 0s 4448KB
stdin
Standard input is empty
stdout
0