# BZOJ1057: [ZJOI2007]棋盘制作

## 1057: [ZJOI2007]棋盘制作

Time Limit: 20 Sec  Memory Limit: 162 MB
Submit: 1329  Solved: 664
[Submit][Status]

3 3
1 0 1
0 1 0
1 0 0

4
6

## Source

h[i]表示 i 向上满足黑白相间的高度

l 取max，r 取min，更新答案即可

1.a[i-1,j]写成a[i,j-1]。。。

2.l 本该取 max，取成了 min。。。

 1 const maxn=2000+100;
2 var a:array[0..maxn,0..maxn] of longint;
3     h,l,r,sta,l1,l2,r1,r2:array[0..maxn] of longint;
4     n,m,i,j,k,ans1,ans2,top,tmp:longint;
5     function min(x,y:longint):longint;
6      begin
7      if x<y then exit(x) else exit(y);
8      end;
9     function max(x,y:longint):longint;
10      begin
11      if x>y then exit(x) else exit(y);
12      end;
13
14 procedure init;
15  begin
17    fillchar(a,sizeof(a),60);
18    for i:=1 to n do
19     begin
20      for j:=1 to m do read(a[i,j]);
21     end;
22  end;
23 procedure main;
24  begin
25    h[0]:=-1;h[m+1]:=-1;ans1:=0;ans2:=0;
26    for i:=1 to n do
27     begin
28      for j:=1 to m do if a[i,j]=a[i-1,j] xor 1  then inc(h[j]) else h[j]:=1;
29      top:=0;
30      for j:=1 to m+1 do
31       begin
32       while (top>0) and (h[j]<h[sta[top]]) do
33        begin
34        r1[sta[top]]:=j-1;dec(top);
35        end;
36       inc(top);sta[top]:=j;
37       end;
38      top:=0;
39      for j:=m downto 0 do
40       begin
41       while (top>0) and (h[j]<h[sta[top]]) do
42        begin
43        l1[sta[top]]:=j+1;dec(top);
44        end;
45       inc(top);sta[top]:=j;
46       end;
47      for j:=1 to m do
48        begin
49        if a[i,j]<>a[i,j-1] xor 1 then tmp:=j;
50        l2[j]:=tmp;
51        end;
52      for j:=m downto 1 do
53        begin
54        if a[i,j]<>a[i,j+1] xor 1 then tmp:=j;
55        r2[j]:=tmp;
56        end;
57      for j:=1 to m do
58        begin
59        l[j]:=max(l1[j],l2[j]);
60        r[j]:=min(r1[j],r2[j]);
61        ans1:=max(ans1,h[j]*(r[j]-l[j]+1));
62        ans2:=max(ans2,sqr(min(h[j],r[j]-l[j]+1)));
63        end;
64      //for j:=1 to m do writeln(j,' ',l1[j],' ',l2[j],' ',r1[j],' ',r2[j]);
65     end;
66  writeln(ans2);
67  writeln(ans1);
68  end;
69
70 begin
71   assign(input,'input.txt');assign(output,'output.txt');
72   reset(input);rewrite(output);
73   init;
74   main;
75   close(input);close(output);
76 end.   
View Code

posted @ 2014-08-11 17:54  ZYF-ZYF  Views(...)  Comments(... Edit 收藏