PBCWRI - Writing

Tác giả: RR

Ngôn ngữ: Pascal

{$R-,Q-}
const
  FINP='';
  FOUT='';
  MAXN=3000000;
var
  kq,m,n:longint;
  a,b:ansistring;
  ca,cb:array['A'..'z'] of longint;
procedure inp; inline;
var
  f:text;
begin
  assign(f,FINP); reset(f);
  readln(f,m,n);
  readln(f,a);
  readln(f,b);
  close(f);
end;
function check:boolean; inline;
var
  ch:char;
begin
  for ch:='A' to 'z' do
    if ca[ch]<>cb[ch] then exit(false);
  exit(true);
end;
procedure solve; inline;
var
  i,j:longint;
begin
  kq:=0;
  if m>n then exit;
  for i:=1 to m do inc(ca[a[i]]);
  for i:=1 to m do inc(cb[b[i]]);
  if check then kq:=1;
  for i:=m+1 to n do
    begin
      inc(cb[b[i]]); dec(cb[b[i-m]]);
      if check then inc(kq);
    end;
end;
procedure ans; inline;
var
  f:text;
begin
  assign(f,FOUT); rewrite(f);
  writeln(f,kq);
  close(f);
end;
begin
  inp;
  solve;
  ans;
end.

Download