Bzoj1057: [zjoi2007] Board creation

Source: Internet
Author: User
1057: [zjoi2007] Time Limit: 20 sec memory limit: 162 MB
Submit: 1329 solved: 664
[Submit] [Status] Description

Chess is one of the world's oldest game games. It is said that chess originated from the idea of Yijing. The board is an 8x8 black and white matrix, which corresponds to the eight sixty-fourteen hexagrams, and the black and white correspond to the yin and yang. Q, our hero, is a fan of chess. As a top player, he is no longer satisfied with ordinary boards and rules, so he and his good friend John decided to expand the board to adapt to their new rules. Q finds a rectangular piece of paper consisting of n * m square grids, each of which is painted in either black or white. Q wants to cut a part of the paper as a new board. Of course, he wants the board to be as big as possible. However, Q hasn't decided whether to find a square board or a rectangle Board (of course, either way, the Board must be black and white, that is, different colors of adjacent grids ), so he hopes to find the largest square board area and the largest rectangular board area to decide which one is better. So Xiao Q found you who are about to participate in the National Informatics competition. Can you help him?

Input

The first line contains two integers, N and M, indicating the length and width of the rectangular paper. The next n rows contain a 01 matrix of N * m, indicating the color of the rectangular paper (0 indicates white, 1 indicates black ).

Output

Contains two rows. Each row contains an integer. The area of the largest square board that can be found in the first action, and the area of the largest rectangular board that can be found in the second action (note that the square and the rectangle can be intersection or contain ).

Sample input3 3
1 0 1
0 1 0
1 0 0
Sample output4
6
Hint

 

For 20% of data, n, m ≤ 80 for 40% of data, n, m ≤ 400 for 100% of data, n, m ≤ 2000

 

Source

Question:

H [I] indicates that I reaches the black and white height.

First, we can use the monotonic stack to obtain the left and right ranges of H [I] as the minimum values of the interval, and then we can scan the left and right sides to find out where the farthest horizontal expansion meets the requirements of black and white

L use Max, r use min, and update the answer.

Several Sb errors were made:

1. A [I-1, J] written as a [I, J-1]..

2. l should have taken Max, and Min...

Code:

 1 const maxn=2000+100; 2 var a:array[0..maxn,0..maxn] of longint; 3     h,l,r,sta,l1,l2,r1,r2:array[0..maxn] of longint; 4     n,m,i,j,k,ans1,ans2,top,tmp:longint; 5     function min(x,y:longint):longint; 6      begin 7      if x<y then exit(x) else exit(y); 8      end; 9     function max(x,y:longint):longint;10      begin11      if x>y then exit(x) else exit(y);12      end;13 14 procedure init;15  begin16    readln(n,m);17    fillchar(a,sizeof(a),60);18    for i:=1 to n do19     begin20      for j:=1 to m do read(a[i,j]);21     end;22  end;23 procedure main;24  begin25    h[0]:=-1;h[m+1]:=-1;ans1:=0;ans2:=0;26    for i:=1 to n do27     begin28      for j:=1 to m do if a[i,j]=a[i-1,j] xor 1  then inc(h[j]) else h[j]:=1;29      top:=0;30      for j:=1 to m+1 do31       begin32       while (top>0) and (h[j]View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.