ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1307. Archiver

2admins! (Fail (Validator))
Posted by Stupnikov Pavel 27 Apr 2004 00:09
I got Fail (Validator). In the e-mail was written "Either it is 'Wrong Answer' or it is a bug". So can you check your validator and tell me whose bug it is.

Edited by author 27.04.2004 00:10
Re: 2admins! (Fail (Validator))
Posted by Stupnikov Pavel 28 Apr 2004 19:51
It is easier to debug your validator myself, than wait when you did it yourself: I think, that if archive crashes (ASCESS_VIOLATION), I should get WA or AV, but not Fail(Validator).

Edited by author 28.04.2004 20:22
I get Fail (Validator) on test #3 too! Can anyone help me?
I suppose it's alright to use characters whose ASCII codes are bigger than 126.

-------------------
program ural1307;
const
  maxtxtlen=200000;
  maxchr=255;
var
  text:array[1..maxtxtlen]of char;
  count:array[0..maxchr]of longint;
  sum:array[0..maxchr,0..maxchr]of longint;
  code:array[0..maxchr]of string;
  len:longint;
  i:byte;
procedure readtext;
  var
    i,j:word;
  begin
    repeat
      inc(len);
      read(text[len]);
      inc(count[ord(text[len])]);
    until eof;
    for i:=0 to maxchr do begin
      sum[i,i]:=count[i];
      for j:=i+1 to maxchr do
        sum[i,j]:=sum[i,j-1]+count[j];
    end;
  end;
procedure cipher(s,t:byte);
  var
    l,r,m:byte;
    c:longint;
  begin
    while (count[s]=0) and (s<=t) do inc(s);
    while (count[t]=0) and (s<=t) do dec(t);
    if s>t then exit;
    if s=t then begin
      if code[s]='' then code[s]:='0';
      exit;
    end;
    l:=s;r:=t;c:=sum[s,t] div 2;
    repeat
      m:=(l+r) div 2;
      if sum[s,m]<c then l:=m+1 else r:=m;
    until l=r;
    if l=t then dec(l);
    for m:=s to l do code[m]:=code[m]+'0';
    for m:=l+1 to t do code[m]:=code[m]+'1';
    cipher(s,l);
    cipher(l+1,t);
  end;
function ch(s:string):char;
  var
    d,i:byte;
  begin
    d:=0;
    for i:=1 to 7 do
      d:=d shl 1+ord(s[i]='1');
    ch:=chr(d+40);
  end;
procedure compress;
  const
    complen=240;
  var
    i:longint;
    s,t:string;
  procedure join(c:char);
    begin
      t:=t+c;
      if length(t)>=complen then begin
        writeln('d(''',t,''');');
        t:='';
      end;
    end;
  begin
    writeln('{PAS}');
    write('const code:array[0..',maxchr,']of string=(');
    for i:=0 to maxchr do begin
      if count[i]=0 then write('''''') else write('''',code[i],'''');
      if i=maxchr then write(');') else write(',');
      if i mod 16=15 then writeln;
    end;
    writeln('m=',maxchr,';l=',len,';');
    writeln('var a:ansistring;c:longint;');
    writeln('function b(c:char):string;');
    writeln('var d,i:byte;s:string;');
    writeln('begin');
    writeln('s:='''';d:=ord(c)-40;');
    writeln('for i:=1 to 7 do begin');
    writeln('s:=chr(48+ord(odd(d)))+s;');
    writeln('d:=d shr 1;');
    writeln('end;');
    writeln('b:=s;');
    writeln('end;');
    writeln('procedure e;');
    writeln('var i:byte;');
    writeln('begin');
    writeln('for i:=0 to m do');
    writeln('if (code[i]>'''') and (copy(a,1,length(code[i]))=code[i]) then begin');
    writeln('write(chr(i));');
    writeln('break;');
    writeln('end;');
    writeln('delete(a,1,length(code[i]));inc(c);');
    writeln('end;');
    writeln('procedure d(s:string);');
    writeln('var i:byte;');
    writeln('begin');
    writeln('for i:=1 to length(s) do');
    writeln('a:=a+b(s[i]);');
    writeln('while length(a)>20 do');
    writeln('e;');
    writeln('end;');
    writeln('begin');

    s:='';t:='';
    for i:=1 to len do begin
      s:=s+code[ord(text[i])];
      while length(s)>6 do begin
        join(ch(copy(s,1,7)));
        delete(s,1,7);
      end;
    end;
    if s>'' then begin
      while length(s)<7 do s:=s+'0';
      join(ch(s));
    end;
    if t>'' then writeln('d(''',t,''');');

    writeln('while c<l do e;');
    writeln('end.');
  end;
begin
  readtext;
  cipher(0,maxchr);
  compress;
end.

Edited by author 03.10.2004 17:09