记录编号 98582 评测结果 AAAAAAA
题目名称 [HAOI 2005]破译密文 最终得分 100
用户昵称 Gravatar麦田之上 是否通过 通过
代码语言 Pascal 运行时间 0.001 s
提交时间 2014-04-23 20:29:26 内存使用 0.20 MiB
显示代码纯文本
PROGRAM encrypt;//HAOI2005 poyimiwen;COGS 20;
CONST
  fin='encrypt.in';
  fout='encrypt.out';
  maxn=10000+5;
TYPE
  str=array[1..1000]of char;
VAR
  f:array[0..maxn]of integer;
  o:array[2..maxn]of boolean;
  p:array['a'..'z',1..2]of integer;
  s1,s2:array[1..1000]of integer;
  n,u:byte;
  i,j,f1,f2,l1,l2,l,temp,ans:integer;
  c:char;
FUNCTION father(x:integer):integer;
  var temp:integer;
  begin
    if (f[x]=x)then exit(x);
    temp:=father(f[x]);
    f[x]:=temp;
    exit(temp);
  End;
PROCEDURE tuichu;
  begin
    write(0);
    close(output);
    halt;
  End;
BEGIN
  assign(input,fin);reset(input);
  assign(output,fout);rewrite(output);
  readln;
  readln;
  readln(n);
  j:=2;
  for i:=1 to n do
   begin
     readln(c,u);
     p[c,1]:=j;
     inc(j,u);
     p[c,2]:=j-1;
   ENd;
  l:=j-1;
  f[1]:=1;
  for i:=2 to l do f[i]:=i;
  close(input);assign(input,fin);reset(input);
  l1:=0;
  repeat
    read(c);
    case c of
      '0':begin inc(l1);s1[l1]:=0;end;
      '1':begin inc(l1);s1[l1]:=1;end;
      else for i:=p[c,1] to p[c,2] do
            begin
              inc(l1);
              s1[l1]:=i;
            End;
    End;
  until eoln;
  readln;

  l2:=0;
  repeat
    read(c);
    case c of
      '0':begin;inc(l2);if s1[l2]=1 then tuichu;s2[l2]:=0;end;
      '1':begin;inc(l2);if s1[l2]=0 then tuichu;s2[l2]:=1;end;
      else for i:=p[c,1] to p[c,2] do
            begin
              inc(l2);
              s2[l2]:=i;
            End;
    End;
  until eoln;
  {read}
  for i:=1 to l1 do
  begin
    f1:=father(s1[i]);
    f2:=father(s2[i]);
    if f1+f2=1 then tuichu;
    if f1>f2 then f[f1]:=f2
             else f[f2]:=f1;
  End;
  for i:=1 to l do
  begin
    f[i]:=father(f[i]);
    temp:=f[i];
    if (temp<>0)and(temp<>1)and(temp<>i)and(o[temp]=False)then begin inc(ans);o[temp]:=True;end;
  End;
  writeln(1 shl ans);
  close(output);
END.