洛谷P1169 棋盘制作(悬线法)

题目链接:https://www.luogu.org/problemnew/show/P1169

#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pqueue priority_queue
#define NEW(a,b) memset(a,b,sizeof(a))
const double pi=4.0*atan(1.0);
const double e=exp(1.0);
const int maxn=1e6+8;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+7;
const ULL base=1e7+7;
using namespace std;
int a[2008][2008];
int l[2008][2008],r[2008][2008],u[2008][2008];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d",&a[i][j]);
        }
        l[i][1]=1;r[i][m]=m;
        for(int j=2;j<=m;j++){
            if(a[i][j]!=a[i][j-1]){
                l[i][j]=l[i][j-1];
            }
            else{
                l[i][j]=j;
            }
        }
        for(int j=m-1;j>=1;j--){
            if(a[i][j]!=a[i][j+1]){
                r[i][j]=r[i][j+1];
            }
            else{
                r[i][j]=j;
            }
        }
    }
    int maxa=0,maxb=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(i>1&&a[i][j]!=a[i-1][j]){
                u[i][j]=u[i-1][j]+1;
                l[i][j]=max(l[i][j],l[i-1][j]);
                r[i][j]=min(r[i][j],r[i-1][j]);
            }
            else{
                u[i][j]=1;
            }
            maxa=max(maxa,(r[i][j]-l[i][j]+1)*u[i][j]);
            maxb=max(maxb,min(r[i][j]-l[i][j]+1,u[i][j])*min(r[i][j]-l[i][j]+1,u[i][j]));
        }
    }
    cout<<maxb<<endl<<maxa<<endl;
}

 

posted @ 2018-10-03 09:53  我要见血小板  阅读(145)  评论(0编辑  收藏  举报