Pagini recente » Cod sursa (job #1205769) | Cod sursa (job #1590675) | Cod sursa (job #1630481) | Cod sursa (job #1862571) | Cod sursa (job #41652)
Cod sursa(job #41652)
//infoarena matrix 178;
const max = 1000;
var a,b:array[1..max,1..max] of char;
t: array[0..max,0..max] of longint;
lit: array['a'..'z'] of longint;
rez: array[1..max,1..max] of boolean;
n,m:integer;
nrmat:longint;
procedure citire;
var i,j:integer;
buf:array[1..32768] of byte;
f:text;
begin
assign(f,'matrix.in'); reset(f); settextbuf(f,buf);
readln(f,m,n);
for i:=1 to m do
begin
for j:=1 to m do
read(f,a[i,j]);
readln(f);
end;
for i:=1 to n do
begin
for j:=1 to n do
begin
read(f,b[i,j]);
inc(lit[b[i,j]]);
end;
readln(f);
end;
close(f);
end;
procedure calc;
var i,j:integer;
x:longint;
c:char;
begin
for c:='a' to 'y'do
begin
fillchar(t,sizeof(t),0);
for i:=1 to m do
for j:=1 to m do
begin
t[i,j]:=t[i-1,j]+t[i,j-1]-t[i-1,j-1];
if a[i,j] = c then inc(t[i,j]);
end;
for i:=n to m do
for j:=n to m do
begin
x:=t[i,j]-t[i-n,j]-t[i,j-n]+t[i-n,j-n];
if x <> lit[c] then
rez[i,j]:=true;
end;
end;
for i:=n to m do
for j:=n to m do
if not rez[i,j] then inc(nrmat);
end;
begin
citire;
calc;
assign(output,'matrix.out'); rewrite(output);
writeln(nrmat);
close(output);
end.