CF713D.Animals and Puzzle

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Owl Sonya gave a huge lake puzzle of size n × m to hedgehog Filya as a birthday present. Friends immediately started to assemble the puzzle, but some parts of it turned out to be empty — there was no picture on them. Parts with picture on it are denoted by 1, while empty parts are denoted by 0. Rows of the puzzle are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m.

Animals decided to complete the picture and play with it, as it might be even more fun! Owl and hedgehog ask each other some queries. Each query is provided by four integers _x_1, _y_1, _x_2, _y_2 which define the rectangle, where (_x_1, _y_1) stands for the coordinates of the up left cell of the rectangle, while (_x_2, _y_2) stands for the coordinates of the bottom right cell. The answer to the query is the size of the maximum square consisting of picture parts only (only parts denoted by 1) and located fully inside the query rectangle.

Help Sonya and Filya answer t queries.

猫头鹰索尼娅送给刺猬菲利娅一个尺寸为 n×mn \times m 的巨型湖景拼图作为生日礼物。朋友们立刻开始拼装这个拼图,但其中一些部分却是空的——上面没有图案。有图案的部分用 1 表示,空的部分用 0 表示。拼图的行从上到下编号为 11 到 nn,列从左到右编号为 11 到 mm。

动物们决定补全图案并一起玩耍,因为这样可能更有趣!猫头鹰和刺猬会互相提出若干查询。每个查询由四个整数 x1,y1,x2,y2x_1, y_1, x_2, y_2 给出,定义了一个矩形区域:(x1,y1)(x_1, y_1) 表示该矩形左上角单元格的坐标,(x2,y2)(x_2, y_2) 表示右下角单元格的坐标。查询的答案是:完全位于该查询矩形内部、且仅由图案部分(即全为 1 的单元格)构成的最大正方形的边长。

请帮助索尼娅和菲利娅回答 tt 个查询。

输入格式

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 1000) — sizes of the puzzle.

Each of the following n lines contains m integers a__ij. Each of them is equal to 1 if the corresponding cell contains a picture and 0 if it's empty.

Next line contains an integer t (1 ≤ t ≤ 1 000 000) — the number of queries.

Then follow t lines with queries' descriptions. Each of them contains four integers _x_1, _y_1, _x_2, _y_2 (1 ≤ _x_1 ≤ _x_2 ≤ n, 1 ≤ _y_1 ≤ _y_2 ≤ m) — coordinates of the up left and bottom right cells of the query rectangle.

输入的第一行包含两个整数 nn 和 mm(1 ≤ n, m ≤ 10001 ≤ n, m ≤ 1000)——拼图的尺寸。

接下来的 nn 行中,每行包含 mm 个整数 aija_{ij}。若对应单元格中包含图像,则该值为 11;若为空,则为 00。

下一行包含一个整数 tt(1 ≤ t ≤ 1 000 0001 ≤ t ≤ 1\,000\,000)——查询次数。

随后是 tt 行,每行描述一个查询:包含四个整数 x1x_1, y1y_1, x2x_2, y2y_2(1 ≤ x1 ≤ x2 ≤ n1 ≤ x_1 ≤ x_2 ≤ n, 1 ≤ y1 ≤ y2 ≤ m1 ≤ y_1 ≤ y_2 ≤ m)——查询矩形的左上角与右下角单元格的坐标。

输出格式

Print t lines. The i-th of them should contain the maximum size of the square consisting of 1-s and lying fully inside the query rectangle.

输出 tt 行。其中第 ii 行应包含完全位于第 ii 个查询矩形内部、且仅由 1 组成的最大正方形的边长。

输入输出样例

  • 输入#1

    3 4
    1 1 0 1
    0 1 1 0
    0 1 1 0
    5
    1 1 2 3
    2 1 3 2
    3 2 3 4
    1 1 3 4
    1 2 3 4

    输出#1

    1
    1
    1
    2
    2

输入解题思路,AI测评打分。不知道怎么写?

首页