题目链接:传送门
题解:
方法一见 【codevs1159】最大全0子矩阵
枚举每一个障碍点作为左边界扩展极大子矩阵,复杂度 <nobr> O(S2) </nobr>,其中 <nobr> S </nobr>为障碍点数目
//by sdfzchy
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
struct node
{
int x,y;
}p[5050];
int n,m,tot,ans;
bool cmp(node a,node b) {return a.x<b.x;}
bool cmpp(node a,node b){return a.y<b.y;}
bool cmppp(node a,node b){return a.y>b.y;}
int main()
{
scanf("%d%d%d",&n,&m,&tot);
for(int i=1;i<=tot;i++) scanf("%d%d",&p[i].x,&p[i].y);
p[++tot]=(node){0,0};p[++tot]=(node){0,m};
p[++tot]=(node){n,0};p[++tot]=(node){n,m};
sort(p+1,p+tot+1,cmp);
for(int i=2;i<=tot;i++) ans=max(ans,(p[i].x-p[i-1].x)*m);
sort(p+1,p+tot+1,cmpp);
for(int i=1;i<tot;i++)
{
int U=0,D=n;
for(int j=i+1;j<=tot;j++)
{
if(p[i].y==p[j].y) continue;
ans=max(ans,(p[j].y-p[i].y)*(D-U));
if(p[j].x>=D||p[j].x<=U) continue;
if(p[j].x<=p[i].x) U=p[j].x;
if(p[j].x>=p[i].x) D=p[j].x;
if(p[j].x==p[i].x) break;
}
}
sort(p+1,p+tot+1,cmppp);
for(int i=1;i<tot;i++)
{
int U=0,D=n;
for(int j=i+1;j<=tot;j++)
{
if(p[i].y==p[j].y) continue;
ans=max(ans,(p[i].y-p[j].y)*(D-U));
if(p[j].x>=D||p[j].x<=U) continue;
if(p[j].x<p[i].x) U=p[j].x;
if(p[j].x>p[i].x) D=p[j].x;
if(p[j].x==p[i].x) break;
}
}
printf("%d\n",ans);
return 0;
}