Блог пользователя chepestb

Автор chepestb, история, 2 года назад, По-английски

I am stuck on problem to count total number of such squares whose boundary consists of ones only in binary matrix.Please help. Problem Link:

  • Проголосовать: нравится
  • +9
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

On a surface, the idea is to work on each diagonal seperately as each diagonal will have the top leftmost and bottom rightmost point of a square. Now for each element,if it's the top leftmost element, then the bottom-rightmost element will lie in some range,Same thing holds for bottom rightmost elements. It reduces the problem to finding total number of relevant intersections of ranges in each diagonal which can be done in nlogn for each diagonal.