洛谷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+;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+;
const ULL base=1e7+;
using namespace std;
int a[][];
int l[][],r[][],u[][];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&a[i][j]);
}
l[i][]=;r[i][m]=m;
for(int j=;j<=m;j++){
if(a[i][j]!=a[i][j-]){
l[i][j]=l[i][j-];
}
else{
l[i][j]=j;
}
}
for(int j=m-;j>=;j--){
if(a[i][j]!=a[i][j+]){
r[i][j]=r[i][j+];
}
else{
r[i][j]=j;
}
}
}
int maxa=,maxb=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(i>&&a[i][j]!=a[i-][j]){
u[i][j]=u[i-][j]+;
l[i][j]=max(l[i][j],l[i-][j]);
r[i][j]=min(r[i][j],r[i-][j]);
}
else{
u[i][j]=;
}
maxa=max(maxa,(r[i][j]-l[i][j]+)*u[i][j]);
maxb=max(maxb,min(r[i][j]-l[i][j]+,u[i][j])*min(r[i][j]-l[i][j]+,u[i][j]));
}
}
cout<<maxb<<endl<<maxa<<endl;
}
上一篇:弱类型dynamic与var


下一篇:C# dynamic与var的区别