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 1164. Fillword

I have got WA.What is wrong with my program?
Posted by Tony 7 Oct 2002 15:16
const
 max=10;
 maxp=100;

var
 g:array[1..max,1..max]of char;
 lt:array[1..max,1..max]of byte;
 pri:array['A'..'Z']of byte;
 m,n,p,mark:integer;
 s:string;
procedure find_work(t,x,y:integer);
  var i,j:integer;
 begin
  if t>m then begin mark:=1;exit;end;
   for i:=1 to n do
    for j:=1to m do
     if(s[t]=g[i,j])and((abs(i-x)+abs(j-y)=1)or((x=0)and(y=0)))
      then begin
       inc(lt[i,j]);
       find_work(t+1,i,j);
       if mark=1 then exit;
       dec(lt[i,j]);
      end;
 end;
procedure init_work;
  var i,j:integer;
 begin
  fillchar(g,sizeof(g),0);
  fillchar(lt,sizeof(lt),0);
  fillchar(pri,sizeof(pri),0);
  readln(n,m,p);
  for i:=1 to n do
   begin
    for j:=1 to m do read(g[i,j]);
    readln;
   end;
  for i:=1 to p do
   begin
    readln(s);
    mark:=0;
    find_work(1,0,0);
   end;
  end;
procedure outit_work;
  var ch:char;
      i,j:integer;
 begin
  for i:=1 to n do for j:=1 to m do if lt[i,j]=0 then inc(pri[g
[i,j]]);
  for ch:='A' to 'Z' do
   for i:=1 to pri[ch] do write(ch);
 end;
begin
 init_work;
 outit_work;
end.