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

Автор Christian_D, история, 6 лет назад, По-английски

The problem is here. My latest attempt is here.

I've implemented a version of this algorithm. It works for the smaller tests, however in the worst case (100000x100000 matrix, nothing blurry) my implementation still takes about 13 seconds.

I've optimized it as far as I'm able to. Is there something I'm missing? Or another approach entirely? I'm stuck.

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

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

Try a binary search on the length of the square. Complexity: Nlog(N).

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I'm not sure how I could use binary search to solve the problem. Can you elaborate?

    • »
      »
      »
      6 лет назад, скрыть # ^ |
      Rev. 3  
      Проголосовать: нравится 0 Проголосовать: не нравится

      The key is "all the non-blurred pixels are connected in such a way that any horizontal or vertical line drawn between two non-blurred pixels goes only through non-blurred pixels". That means that to check if a square is inside the non-blurred part you only need to check that the four vertexes are inside. Each row i contains a segment [a_i, b_i] of non-blurred pixels. To check whether a square of length k+1 fits on the non-blurred part, denote by m_i = max(a_i, a_{i+k}). You need to check that (i, m_i) (i+k, m_i), (i, m_i+k) (i+k, m_i+k) all belong to the non-blurred parts. This can be done in O(1) time. Thus in O(N) time, you check if a square of side length (k+1) fits.