BZOJ1057【单调栈】
来源:互联网 发布:淘宝没有3c会怎么样 编辑:程序博客网 时间:2024/06/09 13:07
无限仰慕KeyID讲的不用单调栈的方法.
/* I will wait for you */#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> PII;const int maxn=2010;const int maxm=1010;const int maxs=26;const int INF=1<<29;const int P=1000000007;const double error=1e-9;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9') f=(ch=='-'?-1:1),ch=getchar();while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}int n,m,ansa,ansb,ma[maxn][maxn],h0[maxn][maxn],h1[maxn][maxn],l[maxn],r[maxn],q[maxn];int main(){n=read(),m=read();for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ma[i][j]=read();for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)h0[i][j]=ma[i][j]?0:h1[i-1][j]+1,h1[i][j]=ma[i][j]?h0[i-1][j]+1:0;for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if((i+j)&1) swap(h0[i][j],h1[i][j]);for(int i=1;i<=n;i++){for(int j=1,top=0;j<=m;j++){while(top&&h0[i][q[top]]>=h0[i][j]) top--;l[j]=top?q[top]+1:1,q[++top]=j;}for(int j=m,top=0;j>=1;j--){while(top&&h0[i][q[top]]>=h0[i][j]) top--;r[j]=top?q[top]-1:m,q[++top]=j;}for(int j=1;j<=m;j++) {ansa=max(ansa,h0[i][j]*(r[j]-l[j]+1));ansb=max(ansb,min(h0[i][j],r[j]-l[j]+1)*min(h0[i][j],r[j]-l[j]+1));}}for(int i=1;i<=n;i++){for(int j=1,top=0;j<=m;j++){while(top&&h1[i][q[top]]>=h1[i][j]) top--;l[j]=top?q[top]+1:1,q[++top]=j;}for(int j=m,top=0;j>=1;j--){while(top&&h1[i][q[top]]>=h1[i][j]) top--;r[j]=top?q[top]-1:m,q[++top]=j;}for(int j=1;j<=m;j++) {ansa=max(ansa,h1[i][j]*(r[j]-l[j]+1));ansb=max(ansb,min(h1[i][j],r[j]-l[j]+1)*min(h1[i][j],r[j]-l[j]+1));}}printf("%d\n%d\n",ansb,ansa);return 0;}
0 0
- BZOJ1057【单调栈】
- BZOJ1057 棋盘制作 单调栈
- [BZOJ1057]ZJOI2007棋盘制作|DP|单调栈
- 单调栈——BZOJ1057/Luogu1169 [ZJOI2007]棋盘制作
- [BZOJ1057][ZJOI2007]棋盘制作 (单调栈/悬线法)
- 【BZOJ1057】[ZJOI2007]棋盘制作【最大全0子矩阵】【单调栈】【悬链法】
- BZOJ1057
- 单调栈 单调队列
- 单调栈
- 单调栈
- 单调栈
- 单调栈
- 单调栈
- 单调栈
- 单调栈
- 单调栈
- 单调栈
- 单调栈
- mysql 启动错误
- 小结几个php操作office的类库
- 项目难题之PC和ARM串口莫名其妙无法通信的问题
- 联网框架--->volley初步了解
- hibernate缓存机制详细分析
- BZOJ1057【单调栈】
- C++ 简单贪吃蛇游戏
- 2.4带数据标签的散点图
- 【使用笔记】git在macos上的使用初步
- 第二章
- 苹果开发吐槽
- nginx 搭建 wordpress
- [Java]leetcode6 ZigZag Conversion
- 输入输出控制方式