代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,b[55][55],ans[55][55];
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cin>>b[i][j];
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
for(int x = 1; x <= n; x++) {
for(int y = 1; y <= m; y++) {
if(b[i][j] == b[x][y]) {
ans[i][j] = max(ans[i][j], (i - x) * (i - x) + (j - y) * (j - y));
}
}
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<ans[i][j]<<" ";
cout<<endl;
}
return 0;
}