比赛 20100927 评测结果 AWWWAAAAAEEEEEEE
题目名称 翻译玛雅著作 最终得分 37
用户昵称 王者自由 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-27 22:03:36
显示代码纯文本
program writing;
var ss,i,t:longword; g:word;
  w,a:array[1..3000]of char;
  s:array[1..3000000]of char;
procedure sort(s,t:integer);
var i,j:integer; x,q:char;
begin
  i:=s; j:=t; x:=a[(i+j)div 2];
  repeat
    while a[i]<x do inc(i); while a[j]>x do dec(j);
    if i<=j then
    begin
      q:=a[i]; a[i]:=a[j]; a[j]:=q;
      inc(i); dec(j);
    end;
  until i>j;
  if s<j then sort(s,j);
  if i<t then sort(i,t);
end;
procedure find(n:longword);
var i:longword; r:boolean;
  p:array[1..3000]of char;
begin
  if n>=ss-g then exit;
  for i:=n to n+g do p[i-n+1]:=s[i];
  for i:=1 to g do a[i]:=p[i]; sort(1,g); for i:=1 to g do p[i]:=a[i];
  r:=true;
  for i:=1 to g do if p[i]<>w[i] then begin r:=false; break; end;
  if r then inc(t);
  find(n+1);
end;
begin
  assign(input,'writing.in'); reset(input);
  assign(output,'writing.out'); rewrite(output);
  readln(g,ss);
  for i:=1 to g do read(w[i]); readln;
  for i:=1 to ss do read(s[i]);
  for i:=1 to g do a[i]:=w[i]; sort(1,g); for i:=1 to g do w[i]:=a[i];
  t:=0; find(1);
  writeln(t);
  close(input); close(output);
end.