CF713D.Animals and Puzzle

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Owl Sonya gave a huge lake puzzle of size n×mn×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 11 , while empty parts are denoted by 00 . Rows of the puzzle are numbered from top to bottom with integers from 11 to nn , while columns are numbered from left to right with integers from 11 to mm .

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 x1x_{1} , y1y_{1} , x2x_{2} , y2y_{2} which define the rectangle, where (x1,y1)(x_{1},y_{1}) stands for the coordinates of the up left cell of the rectangle, while (x2,y2)(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 11 ) and located fully inside the query rectangle.

Help Sonya and Filya answer tt queries.

输入格式

The first line of the input contains two integers nn and mm ( 1<=n,m<=10001<=n,m<=1000 ) — sizes of the puzzle.

Each of the following nn lines contains mm integers aija_{ij} . Each of them is equal to 11 if the corresponding cell contains a picture and 00 if it's empty.

Next line contains an integer tt ( 1<=t<=10000001<=t<=1000000 ) — the number of queries.

Then follow tt lines with queries' descriptions. Each of them contains four integers 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 ) — coordinates of the up left and bottom right cells of the query rectangle.

输出格式

Print tt lines. The ii -th of them should contain the maximum size of the square consisting of 11 -s and lying fully inside the query rectangle.

输入输出样例

  • 输入#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
    
首页