`
promiser
  • 浏览: 76632 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

bzoj1057: [ZJOI2007]棋盘制作

    博客分类:
  • oi
阅读更多

详解请看 http://blog.sina.com.cn/s/blog_9aa2786a01011zoj.html

const int N = 2010;
int n, m, Ans1, Ans2, top, sta1[N], sta2[N], h[N];
bool Dat[N][N];

inline void Input() {
    scanf("%d%d", &n, &m);
    int x;
    For(i, 1, n)
		For(j, 1, m) {
			scanf("%d", &x);
			Dat[i][j] = x;
		}
}

inline void push(int h) {
    int x = 1;
    while(sta2[top] > h) {
        Ans1 = max(sqr(min(sta2[top], sta1[top])), Ans1), Ans2 = max(sta2[top] * sta1[top], Ans2);
        if(sta2[--top] >= h) sta1[top] += sta1[top+1];
        else {
			x += sta1[top+1];
			break;
		}
    }
    if(sta2[top] == h) sta1[top] += x;
    else sta2[++top] = h, sta1[top] = x;
}
inline void Solve() {
	int now = 0;
    Ans1 = 1, Ans2 = 1;
    For(i, 1, m) {
        if (Dat[1][i] + Dat[1][i-1] == 1) now++;
		else now = 1;
        Ans2 = max(now, Ans2), h[i] = 1;
    }
    For(i, 2, n) {
        For(j, 1, m) {
            if(Dat[i][j] + Dat[i][j-1] != 1) push(0);
            if(Dat[i][j] + Dat[i-1][j] == 1) h[j]++;
			else h[j] = 1;
            push(h[j]);
        }
        push(0);
    }
    printf("%d\n%d\n", Ans1, Ans2);
}

int main() {
	#ifndef ONLINE_JUDGE
	SETIO("1057");
	#endif
	Input();
	Solve();
	return 0;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics