BZOJ1057[ZJOI2007] Checkerboard production [monotone stack]

Source: Internet
Author: User

Title Description

Chess is one of the oldest game games in the world, with Chinese Weiqi, chess and Japanese chess. It is said that chess originated from the thought of the I Ching, the chessboard is a 8*8 size of black and white square, corresponding to 8,864 gua, black and white corresponding yin and yang.

And our protagonist, the little Q, is a chess enthusiast. As a top-notch player, he was not content with the usual chessboard and rules, so he and his good friend, Little W, decided to expand the chessboard to fit their new rules.

Little Q found a rectangular piece of paper made up of squares of n*m, each of which was painted with one of the two colors of black and white. Little Q wanted to cut some of this paper as a new chessboard, and of course he wanted the chessboard to be as big as possible.

But little Q has not decided to find a square chessboard or a rectangular chessboard (of course, the chessboard must be black and white, that is, the adjacent lattice is different), so he hopes to find the largest square checkerboard area and the largest rectangular checkerboard area, which will determine which is better.

So little Q found the upcoming National Information Science Competition you, can you help him?

Input/output format

Input format:

contains two integers n and m, each representing the length and width of a rectangular piece of paper. The next n rows contain a 01 matrix of N * m, representing the color of the rectangle paper (0 for White and 1 for black).

Output format:

Contains two lines, each containing an integer. The first behavior can be found in the area of the largest square checkerboard, and the second behavior can be found in the area of the largest rectangular checkerboard (note that squares and rectangles can intersect or contain).

Input and Output Sample input example # #:
3 31 0 10 1 01 0 0
Sample # # of output:
46
Description

For 20% of data, N, m≤80

For 40% of data, N, m≤400

For 100% of data, N, m≤2000

I+j an even-numbered XOR, it's perfection 0 or all 1.

The classic monotone stack application (I,J) is the lower right corner of the

The essence of a monotone stack is to find a range of values that extend around

Attention:

1. Square should be used min (l,h) *min (l,h)

2. Do not hit the wrong m and N

////main.cpp//luogu1169////Created by Candy on 14/11/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespacestd;Const intn=2005; inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intN,m,tot[n],a[n][n];structdata{intL,h,pos;} St[n];inttop=0, ans1=1, ans2=1;voidSolintflag) {memset (tot,0,sizeof(tot));  for(intI=1; i<=n;i++) {Top=0;  for(intj=1; j<=m;j++){            if(A[i][j]==flag) tot[j]++; Elsetot[j]=0;            Data t; T.h=tot[j];t.l=1; t.pos=J;  while(top&&st[top].h>=t.h) {                intl=st[top].l+j-1-st[top].pos,h=st[top].h; Ans1=max (Ans1,min (l,h) *min (l,h)); Ans2=max (ans2,l*h); T.L+=ST[TOP].L; Top--; } st[++top]=T; }         while(top) {intL=st[top].l+m-st[top].pos,h=st[top].h; Ans1=max (Ans1,min (l,h) *min (l,h)); Ans2=max (ans2,l*h); Top--; }    }}intMainintargcConst Char*argv[]) {N=read (); m=read ();  for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {A[i][j]=read ();if(! ((I+J) &1)) a[i][j]^=1; } sol (0); Sol (1); printf ("%d\n%d", ANS1,ANS2); return 0;}

BZOJ1057[ZJOI2007] Checkerboard production [monotone stack]

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.