Help me - problem 1002 (+)
There where a lot of people who couldn't get AC for 1002 although
their programs worked well on CEOI tests. I have the smae situation.
Could anyone tell me what's the problem?
Here is my program:
Program Phones;
Const Letters:Array[1..26] Of Char=
('2','2','2','3','3','3','4','4','1','1','5','5','6',
'6','0','7','0','7','7','8','8','8','9','9','9','0');
Abc:String='abcdefghijklmnopqrstuvwxyz';
Var Sol,How,Voc:Array[0..104,0..104] Of Byte;
Fn:Array[0..104,0..104] Of Boolean;
Wor:Array[1..60000] Of String[60];
nw:Word;
s,tr,u:String;
Function f(x,y:Longint):Longint;
Var i,j:Longint;
Begin
If Fn[x,y] Then
f:=Sol[x,y]
Else Begin
Fn[x,y]:=True;
If Voc[x,y]>0 Then Begin
How[x,y]:=y;
Sol[x,y]:=1;
Exit;
End;
For i:=x To y-1 Do Begin
j:=f(x,i); j:=f(i+1,y);
If f(x,i)+f(i+1,y)<Sol[x,y] Then Begin
Sol[x,y]:=f(x,i)+f(i+1,y);
How[x,y]:=i;
End;
End;
End;
End;
Procedure Show(x,y:Longint);
Var i,j:Longint;
Begin
Begin
If Voc[x,y]>0 Then Begin
Write(Wor[Voc[x,y]],' ');
Exit;
End;
Show(x,How[x,y]);
If How[x,y]<y Then
Show(How[x,y]+1,y);
End;
End;
Procedure ReadData;
Var i,j:Longint;
Begin
FillChar(Voc,SizeOf(Voc),0);
FillChar(Fn,SizeOf(Fn),False);
Readln(s);
If s='-1' Then
Halt;
Readln(nw);
For i:=1 To nw Do Begin
Readln(Wor[i]);
tr:='';
For j:=1 To Length(Wor[i]) Do
tr:=tr+Letters[Ord(Wor[i,j])-Ord('a')+1];
For j:=1 To Length(s)-Length(Wor[i])+1 Do
If Copy(s,j,Length(Wor[i]))=tr Then
Voc[j,j+Length(Wor[i])-1]:=i;
End;
FillChar(Sol,SizeOf(Sol),101);
f(1,length(s));
If f(1,Length(s))=101 Then
Writeln('No solution.')
Else Begin
Show(1,Length(s));
Writeln;
End;
End;
Begin
{ Assign(input,'1002.in'); Reset(input);}
While True Do
ReadData;
End.