公式

B - Spiral Galaxy 解説 by en_translator


Since the constraints on \(N\) and \(M\) are small enough, it is sufficient to enumerate all rectangular regions and check if it is point-symmetric.

To enumerate rectangular regions, it is concise to fix the topmost row, bottommost row, leftmost column, and rightmost column, as in the problem statement.

Inside the nested loop that enumerates the rectangular regions, initialize a variable representing whether the region is point-symmetric with false. When you find a pair of cells painted in different colors but supposed to be in the same color if the region were point-symmetric, set the variable to false. Naively enumerating the pairs of cells is also fast enough.

投稿日時:
最終更新: