记录编号 53957 评测结果 AAAAAAAAAA
题目名称 [HAOI 2007]修筑绿化带 最终得分 100
用户昵称 GravatarCAX-DY 是否通过 通过
代码语言 Pascal 运行时间 1.402 s
提交时间 2013-03-07 10:51:58 内存使用 24.30 MiB
显示代码纯文本
uses math;
type ss=record
      s,p:longint;
     end;
var a,b,c,d,m,n,i,j,k,l,h,t,s1,s2,ans:longint; f:array[1..1000,1..1000]of longint;
    q:array[0..1000]of ss; sb,dd,sm,w1,w2,d2:array[1..1000,1..1000]of longint;
procedure ins(x,y:longint);
begin
 while(t>=h)and(q[t].s>=x)do dec(t);
 while(t>h)and(y-q[h].p>=b-d-1)do inc(h);
 inc(t); q[t].s:=x; q[t].p:=y;
end;
procedure ins2(x,y:longint);
begin
 while(t>=h)and(q[t].s>=x)do dec(t);
 while(t>h)and(y-q[h].p>=a-c-1)do inc(h);
 inc(t); q[t].s:=x; q[t].p:=y;
end;
begin
assign(input,'parterre.in'); assign(output,'parterre.out'); reset(input); rewrite(output);
 readln(m,n,a,b,c,d); fillchar(dd,sizeof(dd),$3f);
 for i:=1 to m do begin for j:=1 to n do read(f[i,j]); readln; end;
 for j:=1 to n do
  begin
   s1:=0; s2:=0;
   for i:=1 to m do
    begin
     s1:=s1+f[i,j]; s2:=s2+f[i,j];
     if i>=a then begin sb[i-a+1,j]:=s1; s1:=s1-f[i-a+1,j]; end;
     if i>=c then begin sm[i-c+1,j]:=s2; s2:=s2-f[i-c+1,j]; end;
    end;
  end;
 for i:=1 to m do
  begin
   s1:=0; s2:=0;
   for j:=1 to n do
    begin
     s1:=s1+sb[i,j]; s2:=s2+sm[i,j];
     if j>=b then begin w1[i,j-b+1]:=s1; s1:=s1-sb[i,j-b+1]; end;
     if j>=d then begin w2[i,j-d+1]:=s2; s2:=s2-sm[i,j-d+1]; end;
    end;
  end;
 for i:=2 to m-c+1 do
  begin
   h:=0; t:=-1;
   for j:=2 to n-d+1 do
    begin
     ins(w2[i,j],j);
     if j>=b-d-1 then d2[i,j-b+d+2]:=q[h].s;
    end;
  end;
 for j:=2 to n-d+1 do
  begin
   h:=0; t:=-1;
   for i:=2 to m-c+1 do
    begin
     ins2(d2[i,j],i);
     if i>=a-c-1 then dd[i-a+c+2,j]:=q[h].s;
    end;
  end;
 for i:=1 to m-a+1 do for j:=1 to n-b+1 do if ans<w1[i,j]-dd[i+1,j+1] then ans:=w1[i,j]-dd[i+1,j+1];
 write(ans);
close(input); close(output);
end.