What's wrong with my answer. Help, pls. Posted by meoden 13 Jun 2002 21:25 Can you give me a test. I can't find a test that my pro. run incorectly. Thanks a lot. Here's my pro.: const maxn=101; var a,d:array[1..maxn,1..maxn] of byte; doi:array['('..']'] of char; st:string; n:integer; procedure in_data; begin readln(st); n:=length(st); doi['(']:=')'; doi[')']:='('; doi['[']:=']'; doi[']']:='['; end; procedure solve; var i,j,k:integer; begin fillchar(a,sizeof(a),0); for i:=1 to n do a[i,i]:=1; for i:=1 to n-1 do for j:=i+1 to n do begin a[i,j]:=255; if (st[i]=doi[st[j]]) and (st[i] in ['(','[']) then if a[i+1,j-1]<a[i,j] then begin a[i,j]:=a[i+1,j-1]; d[i,j]:=0; end; for k:=i to j-1 do if a[i,k]+a[k+1,j]<a[i,j] then begin a[i,j]:=a[i,k]+a[k+1,j]; d[i,j]:=k; end; end; end; procedure out(i,j:integer); begin if i>j then exit; if i=j then begin if st[i] in ['(','['] then write(st[i],doi[st[i]]) else write(doi[st[i]],st[i]); end else if d[i,j]=0 then begin write(st[i]); if i+1<=j-1 then out(i+1,j-1); write(st[j]); end else begin out(i,d[i,j]); out(d[i,j]+1,j); end; end; begin in_data; solve; out(1,n); writeln; end. Help me, please Posted by meoden 14 Jun 2002 06:57 You can find test for this problem at http://neerc.ifmo.ru Con meo hu qua > Can you give me a test. > I can't find a test that my pro. run incorectly. > Thanks a lot. > Here's my pro.: > > const maxn=101; > var a,d:array[1..maxn,1..maxn] of byte; > doi:array['('..']'] of char; > st:string; > n:integer; > > procedure in_data; > begin > readln(st); > n:=length(st); > doi['(']:=')'; doi[')']:='('; > doi['[']:=']'; doi[']']:='['; > end; > > procedure solve; > var i,j,k:integer; > begin > fillchar(a,sizeof(a),0); > for i:=1 to n do a[i,i]:=1; > > for i:=1 to n-1 do > for j:=i+1 to n do > begin > a[i,j]:=255; > if (st[i]=doi[st[j]]) and (st[i] in ['(','[']) then > if a[i+1,j-1]<a[i,j] then > begin > a[i,j]:=a[i+1,j-1]; > d[i,j]:=0; > end; > > for k:=i to j-1 do > if a[i,k]+a[k+1,j]<a[i,j] then { you haven't defined the value a[k+1,j] !!! } > begin > a[i,j]:=a[i,k]+a[k+1,j]; > d[i,j]:=k; > end; > end; > end; > > procedure out(i,j:integer); > begin > if i>j then exit; > if i=j then > begin > if st[i] in ['(','['] then write(st[i],doi[st[i]]) > else write(doi[st[i]],st[i]); > end > else if d[i,j]=0 then > begin > write(st[i]); > if i+1<=j-1 then out(i+1,j-1); > write(st[j]); > end > else > begin > out(i,d[i,j]); > out(d[i,j]+1,j); > end; > end; > > begin > in_data; > solve; > out(1,n); > writeln; > end. Thanks, raxtinhac! Posted by meoden 14 Jun 2002 20:44 > > Can you give me a test. > > I can't find a test that my pro. run incorectly. > > Thanks a lot. > > Here's my pro.: > > > > const maxn=101; > > var a,d:array[1..maxn,1..maxn] of byte; > > doi:array['('..']'] of char; > > st:string; > > n:integer; > > > > procedure in_data; > > begin > > readln(st); > > n:=length(st); > > doi['(']:=')'; doi[')']:='('; > > doi['[']:=']'; doi[']']:='['; > > end; > > > > procedure solve; > > var i,j,k:integer; > > begin > > fillchar(a,sizeof(a),0); > > for i:=1 to n do a[i,i]:=1; > > > > for i:=1 to n-1 do > > for j:=i+1 to n do > > begin > > a[i,j]:=255; > > if (st[i]=doi[st[j]]) and (st[i] in ['(','[']) then > > if a[i+1,j-1]<a[i,j] then > > begin > > a[i,j]:=a[i+1,j-1]; > > d[i,j]:=0; > > end; > > > > for k:=i to j-1 do > > if a[i,k]+a[k+1,j]<a[i,j] then > > { you haven't defined the value a[k+1,j] !!! } > > > begin > > a[i,j]:=a[i,k]+a[k+1,j]; > > d[i,j]:=k; > > end; > > end; > > end; > > > > procedure out(i,j:integer); > > begin > > if i>j then exit; > > if i=j then > > begin > > if st[i] in ['(','['] then write(st[i],doi[st[i]]) > > else write(doi[st[i]],st[i]); > > end > > else if d[i,j]=0 then > > begin > > write(st[i]); > > if i+1<=j-1 then out(i+1,j-1); > > write(st[j]); > > end > > else > > begin > > out(i,d[i,j]); > > out(d[i,j]+1,j); > > end; > > end; > > > > begin > > in_data; > > solve; > > out(1,n); > > writeln; > > end. Re: You can find test for this problem at http://neerc.ifmo.ru Posted by meoden 14 Jun 2002 20:52 Thanks. I have seen the page of neerc. Now I've got AC. By the way, can you tell me some other online contest, like neerc. Thanks once more. Maybe no other :-( acm.uva.es acm.timus.ru ace.delos.com but you know them :-) Wow! On neerc you can find ACM World Final 2002. (neerc.ifmo.ru/online) |