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 1121. Branches

i wa too want some test data
Posted by ^oo^ 11 Nov 2002 18:09
const MAXN=15;
type
   data=array[1..4] of 0..1;
var
  d:array[1..MAXN,1..MAXN] of data;
  p:array[1..MAXN,1..MAXN] of 0..1;
  a:array[1..MAXN,1..MAXN] of integer;
  h,w,i,j,k,t,s,pi,pj:integer;
  mmm:data;

function exto(a:data):integer;
var i,s,t:integer;
begin
  s:=0; t:=1;
  for i:=1 to 4 do
  begin
    s:=s+t*a[i];
    t:=t*2;
  end;
  exto:=s;
end;

function equal(a,b:data):boolean;
var i:integer;
begin
  equal:=false;
  for i:=1 to 4 do
    if a[i]<>b[i] then exit;
  equal:=true;
end;

function ok(i,j:integer):boolean;
begin
  if (i<1) or (j<1) or (i>h) or (j>w) then ok:=false else
ok:=true;
end;

procedure add(var a:data; b:data);
var i:integer;
begin
   for i:=1 to 4 do
     if b[i]=1 then a[i]:=1;
end;

begin
  assign(input,'1121.in');
  reset(input);
  read(h,w);
  for i:=1 to h do
  for j:=1 to w do
  begin
    read(s);
    if s<>0 then p[i,j]:=1;
    t:=8;
    for k:=4 downto 1 do
    begin
      if s-t>=0 then begin dec(s,t); d[i,j,k]:=1; end;
      t:=t div 2;
    end;
    writeln(s);
  end;

  for i:=1 to h do
  begin

    for j:=1 to w do
    begin

      a[i,j]:=-1;

      if p[i,j]=0 then
      begin
        for k:=1 to 5 do
        begin
          mmm:=d[i,j];
          for pi:=-k to k do
          begin
            pj:=k-abs(pi);
            if (ok(i+pi,j+pj)) then add(mmm,d[i+pi,j+pj]);
            pj:=-pj;
            if (pj<>0) and (ok(i+pi,j+pj)) then add(mmm,d
[i+pi,j+pj]);
          end;
          if not equal(d[i,j],mmm) then break;
        end;
        a[i,j]:=exto(mmm);
      end;

      write(a[i,j]:2,' ');

    end;
    writeln;

  end;

end.