CREC01 - Đếm hình chữ nhật trên bảng 0-1
Tác giả: khuc_tuan
Ngôn ngữ: Pascal
//{$APPTYPE CONSOLE}
{$MODE DELPHI}
var
m, n, i, j, t : integer;
a : array[0..1001] of char;
h, l, c : array[0..1001] of integer;
r : int64;
begin
readln(m,n);
r := 0;
for i:=1 to m do
begin
readln(a);
for j:=0 to n-1 do
begin
if a[j]='0' then h[j] := 0
else inc(h[j]);
t := j-1;
while (t >= 0) and (h[t] >= h[j]) do t := l[t];
l[j] := t;
c[j] := (j-t) * h[j];
if t >= 0 then c[j] := c[j] + c[t];
r := r + c[j];
end;
end;
writeln(r);
end.