记录编号 21981 评测结果 AAAAAAAAAA
题目名称 牛宫 最终得分 100
用户昵称 Gravatarnick09 是否通过 通过
代码语言 Pascal 运行时间 2.111 s
提交时间 2010-11-16 14:22:38 内存使用 0.42 MiB
显示代码纯文本
var
  n,m:longint;
  a:array[0..201,0..201] of int64;
  sum,b:array[0..201] of int64;
  ans:int64; 

procedure init;
  var
    i,j,x:longint;
  begin
    fillchar(a,sizeof(a),0);
    readln(n,m);
    for i:=1 to n do
      for j:=1 to m do
        begin
          read(x);
          a[i,j]:=a[i-1,j]+a[i,j-1]-a[i-1,j-1]+x;
        end;
  end; 

function cal(x1,y1,x2,y2:longint):int64;
  begin
    cal:=a[x2,y2]-a[x2,y1-1]-a[x1-1,y2]+a[x1-1,y1-1];
  end; 

procedure work;
  var
    i,j,k,p:longint;
  begin
    b[0]:=0; sum[0]:=0;
    ans:=0;
    for i:=1 to m do
      for j:=i to m do
        begin
          for k:=1 to n do sum[k]:=cal(1,i,k,j); 

          for k:=1 to n do
            if sum[k]>sum[k-1] then
              begin
                b[k]:=k;
                for p:=0 to b[k-1] do
                  if sum[p]<sum[k] then
                    begin
                      b[k]:=p;
                      if ans<(k-p)*(j-i+1) then ans:=(k-p)*(j-i+1);
                      break;
                    end;
              end else
            if sum[k]<sum[k-1] then
              begin
                b[k]:=k;
                for p:=b[k-1] to k-1 do
                  if sum[p]<sum[k] then
                    begin
                      b[k]:=p;
                      if ans<(k-p)*(j-i+1) then ans:=(k-p)*(j-i+1);
                      break;
                    end;
              end
            else
              if b[k-1]=k-1 then b[k]:=k else
                begin
                  b[k]:=b[k-1];
                  if ans<(k-b[k])*(j-i+1) then ans:=(k-b[k])*(j-i+1);
                end;
        end; 

    writeln(ans);
  end; 

begin
  assign(input,'long.in'); reset(input);
  assign(output,'long.out'); rewrite(output);
  init;
  work;
  close(input); close(output);
end.