first thought
- the regions which is not surrounded by X is must be started from one side
- mark all the ‘O’ that stretched from sides with BFS
- the other ‘O’ is the surrounded ‘O’
solution
|
|
problem
TLE, from 56/60.
reason
- maybe there’s lots of duplicated iterations.
- have seen the answer, maybe is the class Position took much more time, can solve this by changing the data from 2d into 1d. save the object save-read cost.
modification
|
|
problem
still TLE…
reason
maybe there’s two more iterating in checking the sides? But I think there’s no difference, just try it.
modification
|
|
problem
still TLE… And this time fail at case 54… worse solution…
reason
after have tried lots of modifications, it turns out the position of the code setting the board to ‘.’ does matter. move it from just after the poll operation to in the add queue operation can pass the problem. But I don’t know why. I think they’re the same… I’ll update when I make it clear.
modification
|
|
reason
Finally figure out the reason:
X O O
X O A
X X X
in the situations like above, the point A will be added to the queue twice.so the time cost will grow too much.