ICPC North America Qualifier 2016, Problem E

Alice and Bob are playing Dots and Boxes. The game is played on an
Alice and Bob aren't really in a competitive mood today, so they've just been playing for fun. Hence they aren't following any specific game strategy, and, in particular, even if it's possible to make a move that scores a point or is clearly superior in some way, they won't necessarily make that move. But now they've been playing for a while and neither of them has scored a single point. If neither of them scores a point pretty soon, they may get bored. Given the current state of the game, how many moves could be made, in the worst case, before either Alice or Bob is guaranteed to have scored a point?
Input Specification
Input starts with a line containing an integer
- Cell
is*
, representing dot . - Cell
is.
, representing empty space. - Cell
is|
if dots and have been connected by a line segment, and.
otherwise. - Cell
is-
if dots and have been connected by a line segment, and.
otherwise.
It is guaranteed that no player has scored a point, meaning that no unit squares have been formed.
Output Specification
Output the number of moves that can be made, in the worst case, before either Alice or Bob is guaranteed to have scored a point.
Sample Input 1
3
*-*.*
|.|.|
*.*-*
|...|
*.*.*
Sample Output 1
3
Sample Input 2
2
*.*
...
*.*
Sample Output 2
4
Sample Input 3
4
*-*-*.*
|...|..
*-*-*-*
|.....|
*.*.*-*
|.....|
*-*-*-*
Sample Output 3
5
Comments