Algorithm (C ++ / Graph Theory)

I’ve been struggling with an algorithmic problem for several days, I tried many ways to solve it, but they were not accurate / fast enough, so I rely on you — I'm looking for advice or anything useful.

So the problem is this: there is a square two-dimensional array of bools

bool array[n][n] (n <= 1000)

And as you can imagine, it is full of ones and zeros, but they are always grouped into rectangles, for example:

11100
11100
00001
11100

The algorithm can change two zeros per unit and form as high a shape as possible (the formed shape should not be rectangular) and return the number of units forming this shape. Diagonal connections are not taken into account.

eg:

101
010
101

7. , , 1-2 1000x1000 . , :

  • -, X, Y . , (, ). , , . , 500 000 ( 1000 × 1000) .

  • , , , , , .

, - , . , - , - ? , - () ? , , , .

+4
2

, , . 500 000 500 000 , , .

, : , -, , 1 , 1. OnTurning, . . OnTurnings, , . , OnTurnings , , .

+1

. 1- .

, 0 1 , , , . , . , , , .

, , .

+1

Source: https://habr.com/ru/post/1615329/


All Articles