int r[1010], c[1010];
int a[1010][1010];
int rr[1010][1010], cc[1010][1010];
int main()
{
//freopen("in.txt", "r", stdin);
int n, m;
cin >> n >> m;
f(i, 1, n)f(j, 1, m)scanf("%d", &a[i][j]);
f(i, 1, n)
{
f(j, 1, m)rr[i][j] = a[i][j];
sort(rr[i] + 1, rr[i] + 1 + m);
r[i] = unique(rr[i] + 1, rr[i] + 1 + m)-(rr[i]+1);//当前行个数
}
f(i, 1, m)
{
f(j, 1, n)cc[i][j] = a[j][i];
sort(cc[i] + 1, cc[i] + 1 + n);
c[i] = unique(cc[i] + 1, cc[i] + 1 + n) - (cc[i] + 1);//当前列个数
}
//取行列中比自己小/大的元素大的,即可满足关系
f(i, 1, n)
{
f(j, 1, m)
{
int x1 = lower_bound(rr[i] + 1, rr[i] + 1 + r[i],a[i][j]) - rr[i];
int x2 = lower_bound(cc[j] + 1, cc[j] + 1 + c[j], a[i][j]) - cc[j];
//debug(x1), debug(x2);
printf("%d ", max(x1 - 1, x2 - 1) + max(r[i] - x1, c[j] - x2) + 1);
}
puts("");
}
return 0;
}
C. Skyscrapers(离散化)
最新推荐文章于 2024-08-02 23:55:46 发布