"zjoi2007""luogup1169" Checkerboard Production (and check set

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 Ching, the chessboard is a 8x88 \times 88x8 size black and white square, corresponding to 8,864 gua, black and white corresponding yin and yang.

And our hero 小Q is a chess enthusiast. As a top player, he was not content with the usual chessboard and rules, so he and his best friend 小W decided to expand the board to fit their new rules.

小QA rectangular piece of paper consisting of a lattice of nxmn \times mNxm squares was found, each of which was painted with one of two colors in black and white. 小Qwant to cut a part of this paper as a new chessboard, of course, he wants the chessboard as large as possible.

However, it 小Q has not been decided whether 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, thus deciding which is better.

So 小Q I found you in the National Information Science competition, can you help him?

Input/output format Input Format:

Consists of two integersNnN andMmM, which represents the length and width of the rectangular paper, respectively. The nextNnn rows contain aNXMN \ \times MN Xm 010101 matrix, representing the color of this rectangle of paper (000 denotes white, 11 1 represents 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/Output sample Input Sample # #:Copy
3 31 0 10 1 01 0 0
Sample # # of output:Copy
46
Description

For 20%20\%0% data, n,m≤80n, M≤80n,m≤80

For 40%40\%0% data, n,m≤400n, m≤400< Span class= "katex-html" >n,m≤400

For 100%100\%100data,n,m≤2000n, m≤2000N,M≤200 0

Exercises

One day at noon to eat Super delicious fishmeal, on the way, a contestant asked us,

Do you know what the hang-line method is?!

I didn't know, so I asked him what he was doing, so he voluminous the problem.

I kiao, this is not my school has passed several of the biggest matrix problem?!

The original question is almost as long as this (dot here!) )

Then I reformed the problem, and succeeded in AC.

————————————

In contrast to the original question, we passed the prefix and the condition changed to this bit and the previous one.

And when connected to the left and right, the judgment is different. If the same is not connected.

1 /*2 Qwerta3 P1169 [ZJOI2007] board making4 Accepted5  -6 Code c++,1.5kb7 Submission Time 2018-10-14 21:34:028 time consuming/memory9 29ms, 688KBTen */ One //Luogu-judger-enable-o2 A#include <iostream> -#include <cstdio> -#include <queue> the#include <cmath> - using namespacestd; - #defineR Register - ints[2003]; + inta[2003]; - structemm{ +     intnod,v; A }; at structcmp{ -     BOOL operator() (Emm Qaq,emm qwq) { -         returnqaq.v<qwq.v; -     } - }; -Priority_queue<emm,vector<emm>,cmp>Q; in intsiz[2003],fa[2003]; - BOOLsf[2003]; to intFifaintx) + { -     if(fa[x]==x)returnx; the     returnfa[x]=FIFA (fa[x]); * } $InlinevoidConintXinty)Panax Notoginseng { -     intU=fifa (x), v=Fifa (y); thesiz[u]+=Siz[v]; +fa[v]=u; A     return; the } +InlineintRead () - { $     CharCh=GetChar (); $     intx=0; -      while(!isdigit (CH)) ch=GetChar (); -     if(IsDigit (CH)) {if(ch=='1') x=1; ch=GetChar ();} the     returnx; - }Wuyi intMain () the { -     //freopen ("a.in", "R", stdin); Wu     intn,m; -scanf"%d%d",&n,&m); About     intansz=0, ansc=0; $      for(RintI=1; i<=n;++i) -     { -          for(RintI=1; i<=m;++i) -         { A             intx=read (); +             if(a[i]+x==1) s[i]++; the             Elses[i]=1; -a[i]=x; $ Q.push (EMM) {i,s[i]}); the         } the          for(RintI=1; i<=m;++i) thefa[i]=i,siz[i]=1, sf[i]=0; thea[0]=a[m+1]=2; -          while(!q.empty ()) in         { the             intI=q.top (). nod,x=q.top (). V;q.pop (); thesf[i]=1; About             if(a[i-1]+a[i]==1&&sf[i-1]) theCon (i-1, i); the             if(a[i]+a[i+1]==1&&sf[i+1]) theCon (i,i+1); +             intFi=fifa (i), mi=min (siz[fi],x); -Ansz=max (ansz,mi*mi); theAnsc=max (ansc,siz[fi]*x);Bayi         } the     } theprintf"%d\n%d", ANSZ,ANSC); -     return 0; -}

"zjoi2007""luogup1169" Checkerboard Production (and check set

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.