C++, faster than 100%
\nclass Solution {\npublic:\n    int largest1BorderedSquare(vector<vector<int>>& a){\n        int n=a.size(),m=a[0].size(),left[n+1][m+1],top[n+1][m+1],i,j,ans=
```\nclass Solution {\npublic:\n    int largest1BorderedSquare(vector<vector<int>>& a){\n        int n=a.size(),m=a[0].size(),left[n+1][m+1],top[n+1][m+1],i,j,ans=0;\n        memset(left,0,sizeof(left));\n        memset(top,0,sizeof(top));\n        for(i=1;i<=n;i++){\n            for(j=1;j<=m;j++){\n                if(a[i-1][j-1]==1){\n                    left[i][j]=1+left[i][j-1];\n                    top[i][j]=1+top[i-1][j];\n                    int mn=min(top[i][j],left[i][j]),flag=0;\n                    while(mn>0){\n                        if(top[i][j-mn+1]>=mn&&left[i-mn+1][j]>=mn){\n                            ans=max(ans,mn);flag=1;\n                        }\n                        mn--;if(flag)break;\n                    }\n                }\n            }\n        }\n        return ans*ans;\n        \n    }\n};\n```
[]