PBCWRI - Writing
Tác giả: ladpro98
Ngôn ngữ: Pascal
program pbcwri;
uses math;
const fi='';
var s:ansistring;
ch:array['A'..'z'] of longint;
inp:text;
n,m:longint;
len,res:longint;
procedure input;
var i:longint;
c:char;
begin
assign(inp,fi);
reset(inp);
readln(inp,n,m);
for i:=1 to n do
begin
read(inp,c);
inc(ch[c]);
end;
for c:='A' to 'z' do
if ch[c]>0 then inc(ch[c]);
readln(inp);
readln(inp,s);
close(inp);
end;
procedure process;
var i,j:longint;
begin
i:=1;
while i<=m do
begin
if len>=n then
begin
dec(len);
inc(res);
inc(ch[s[i-n]]);
continue;
end
else
if ch[s[i]]=0 then
begin
for j:=i-1 downto i-len do
inc(ch[s[j]]);
len:=0;
inc(i);
continue;
end
else
if ch[s[i]]=1 then
begin
j:=i-len;
while s[j]<>s[i] do
begin
inc(ch[s[j]]);
inc(j);
dec(len);
end;
inc(i);
continue;
end
else
begin
dec(ch[s[i]]);
inc(len);
inc(i);
continue;
end;
end;
if len>=n then
begin
inc(res);
end
end;
begin
input;
res:=0;
process;
write(res);
end.