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

Common Board

To Tran Nam Trung(+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 9 Mar 2002 22:43
 Thank you Tran Nam Trung for your help on problem 1183. But I didn't
understand your idea. Can you explain it more clearly(espesially
about [i,j] - what i,j mean?)
Re: To Tran Nam Trung(+)
Posted by Tran Nam Trung (trungduck@yahoo.com) 10 Mar 2002 10:43
>  Thank you Tran Nam Trung for your help on problem 1183. But I
didn't
> understand your idea. Can you explain it more clearly(espesially
> about [i,j] - what i,j mean?)
Very happy to help you. D[i,j] means the minnimum number of
characters needed to change the sequence from i to j become correct
sequence. So the answer to the prob is D[1,length(s)].
If you still don't understand me, email me at : trungduck@yahoo.com
I use DP. My program works fine on all NEERC tests but on Timus it get WA! Why? Please, help me!!!(+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 10 Mar 2002 12:23
Program t1183;

Const MaxN = 100;

Var   D        : array[1..MaxN,1..MaxN]of byte;
      i,j,k,q  : integer;
      len      : integer;
      min      : integer;
      S        : String;

Function GetAns(l1,l2 : byte) : String;
Var j : integer;
 begin
  if l1=l2 then begin
    if (s[l1]='(')or(s[l2]=')') then begin
      GetAns:='()';
      exit;
     end;
    if (s[l1]='[')or(s[l2]=']') then begin
      GetAns:='[]';
      exit;
     end;
   end;
  if ((s[l1]='(')and(s[l2]=')'))or
     ((s[l1]='[')and(s[l2]=']')) then begin
       if l1+1<=l2-1 then
        if D[l1,l2]=D[l1+1,l2-1] then begin
         GetAns:=s[l1]+GetAns(l1+1,l2-1)+s[l2];
         exit;
        end;
       if l1+1>l2-1 then begin
         GetAns:=s[l1]+s[l2];
        end;
     end;
  for j:=l1 to l2-1 do
   if D[l1,j]+D[j+1,l2]=D[l1,l2] then begin
    GetAns:=GetAns(l1,j)+GetAns(j+1,l2);
    exit;
   end;
 end;

begin
 Readln(S);
 len:=length(S);
 if len=0 then begin
  Writeln('');
  Halt;
 end;
 fillchar(D,SizeOf(D),255);
 for i:=1 to len do D[i,i]:=1;
 for k:=1 to len-1 do
  for i:=1 to len-k do
   for j:=i+k to len do begin
   if ((s[i]='(')and(s[j]=')'))or
      ((s[i]='[')and(s[j]=']')) then
       if i+1<=j-1 then D[i,j]:=D[i+1,j-1] else D[i,j]:=0;
   for q:=i to j-1 do
    if D[i,q]+D[q+1,j]<D[i,j] then
     D[i,j]:=D[i,q]+D[q+1,j];
  end;
 Writeln(GetAns(1,len));
end.
Re: I use DP. My program works fine on all NEERC tests but on Timus it get WA! Why? Please, help me!!!(+)
Posted by Tran Nam Trung (trungduck@yahoo.com) 11 Mar 2002 18:15
I don't know why. You can try with this test : Input : 100
chacacters "(".
I get AC. I changed my code for a little: I add all compiler options! It's judge bug!!!
Posted by Nazarov Denis (nsc2001@rambler.ru) 11 Mar 2002 19:47
> I don't know why. You can try with this test : Input : 100
> chacacters "(".