Given a n * m matrix of 0s and 1s. For each square,find the sum of Manhattan distances from that square to the first kth nearest 1s.
(Distance to closest 1 + distance to second closest 1 + ...)
n, m <= 2000
k <= n * m
There are at least k ones in the matrix. Thanks!
https://atcoder.jp/contests/abc233/tasks/abc233_h?fbclid=IwAR2FvFmPdn0ly71SBs5cYpRKmZSzmgFxtjpq_JVJHLpME48HhLJbQOJvwx0
I think it's a bit different because I want the sum of the first kth distances, not only the kth.
the idea is a bit similar, in order to calculate the sum of the first kth distance, we need to consider 4 cases to handle |x1 — x2| + |y1 — y2|.
(x1 > x2, y1 > y2)
(x1 < x2, y1 < y2)
(x1 > x2, y1 < y2)
(x1 < x2, y1 > y2)
we can see that we can divide the square into 4 seperate smaller squares to handle that.
Can you provide the source of this task? I think I have something quite close to solving the task but I need some research on it