QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 128 MB Points totaux : 100

#11154. 木匠

Statistiques

Byteasar 想要玩跳棋,但他把棋盘弄丢了。他只找到了一块大小为 $n \times m$ 的木板,被划分为大小相等的正方形格子。每个格子都被涂成了白色或黑色,但这些颜色的排列并不一定符合标准的棋盘图案。在这种情况下,Byteasar 决定利用他的木工经验,用锯子锯出一个棋盘。棋盘是一个由若干格子组成的正方形,其中任意两个相邻的格子颜色必须交替。

Byteasar 不确定是否能在木板上直接找到一个大小合适的正方形。因此,他决定从木板上切下两块三角形碎片,并将它们粘合在一起,从而拼出一个棋盘。(碎片必须是可分离的,但在切下后可以以任何方式旋转。)请帮助 Byteasar 计算他通过这种方法能够得到的最大棋盘尺寸。下图展示了一个 $4 \times 5$ 的木板以及两个可以粘合在一起形成 $3 \times 3$ 棋盘的三角形:

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 1000$):木板的尺寸。接下来的 $n$ 行,每行包含 $m$ 个整数:第 $i$ 行的第 $j$ 个数字 ($1 \le i \le n, 1 \le j \le m$) 描述了木板第 $i$ 行第 $j$ 列格子的颜色。数字 0 表示白色格子,数字 1 表示黑色格子。

输出格式

输出一行一个整数,表示通过从木板上切下两块三角形碎片并粘合在一起所能得到的最大棋盘尺寸。

样例

输入 1

4 5
1 1 0 1 1
0 1 0 1 0
1 0 1 0 0
0 0 1 1 0

输出 1

3

输入 2

3 3
1 1 1
1 1 0
0 1 0

输出 2

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.