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 got WA.....555555555.......Who can help me ?
Posted by hello 11 May 2004 17:56
I got WA on test17. I can't find my mistakes....
I think the sample test is incorrect.
My solution got the answer is :
2 2 -1 2 -1
3 2 2 7 2
1 8 7 5 7
1 6 5 -1 5
-1 1 4 -1 4
But the sample output is :
2 2 -1 2 -1
3 2 2 7 2
1 7 7 5 7
1 5 5 -1 5
-1 1 4 -1 4
I think the sample output is wrong , isn't it ???
Is my answer right ?
Who can tell me ????

This is my code :
const
  Maxn = 200 ;
var
  h : Array [0..Maxn,0..Maxn] Of LongInt ;
  cost : Array [0..Maxn,0..Maxn] Of Int64 ;
  t : Array [0..6*Maxn] Of LongInt ;
  n , m , i , j , k , len : Integer ;

  Function  check ( k : LongInt ) : Boolean ;
    var
      i : Integer ;
    begin
     check := false ;
     if k = 0 then exit ;
     for i := 1 to len do
      if k = t[i] then exit ;
     check := true ;
    end;

  procedure goin  ( x , y , xi , yi : Integer ) ;
    begin
     if check ( h[xi,yi] ) then
      begin
       Inc ( cost[x,y] , h[xi,yi] ) ;
       Inc ( len ) ;
       t[len] := h[xi,yi] ;
      end;
    end;

  procedure Bfs ( x , y , k : Integer ) ;
    var
      i , j , xi , yi : Integer ;
    begin
     len := 0 ;
     for i := 1 to k - 1 do
      begin
       xi := x + i ;
       if xi > n then break ;
       if y + k - i <= m then goin ( x , y , xi , y + k - i ) ;
       if y - k + i >  0 then goin ( x , y , xi , y - k + i ) ;
      end;

     for i := 1 to k - 1 do
      begin
       xi := x - i ;
       if xi < 0 then break ;
       if y + k - i <= m then goin ( x , y , xi , y + k - i ) ;
       if y - k + i >  0 then goin ( x , y , xi , y - k + i ) ;
      end;

     if y + k <= m then goin ( x , y , x , y + k ) ;
     if y - k >  0 then goin ( x , y , x , y - k ) ;
     if x + k <= n then goin ( x , y , x + k , y ) ;
     if x - k >  0 then goin ( x , y , x - k , y ) ;
    end;

begin
 read ( n , m ) ;
 for i := 1 to n do
  for j := 1 to m do
   read ( h[i,j] ) ;

 for i := 1 to n do
  for j := 1 to m do
   if h[i,j] = 0
    then begin
          for k := 1 to 5 do
           begin
            Bfs ( i , j , k ) ;
            if len > 0 then break ;
           end;
         end
    else cost[i,j] := -1 ;

 for i := 1 to n do
  begin
   write ( cost[i,1] ) ;
   for j := 2 to m do
    write ( ' ' , cost[i,j] ) ;
   writeln ;
  end;
end.
Who can give me some test that can find my mistake............
Posted by hello 17 May 2004 20:34
Try like this:
Posted by Y.Y.M. 19 Jun 2004 21:29
According to the problem describe,you should sum up the nearest different types of valus.But it is wrong for the sample text.
However,if you uses 'or' instead of '+',you will obtain the answer as sample output and got AC.

You just have to do is:
Change i:=i+j into i:=i or j
Re: Try like this:
Posted by hello 19 Jun 2004 23:53
I'm sorry . I don't know your meaning .
I have some questions :
1:
I think I just sumed up the nearest different types of valus. Am I right ?
2:
What did you mean " 'or' instead Of '+' "  ?
3:
You said "You just have to do is: Change i:=i+j into i:=i or j " . But I can't find " i:=i+j " in my code .
What did you mean ?

Could you explain to me ?
Thank you very much for helping me !!!
Re: Try like this:
Posted by hello 19 Jun 2004 23:59
Thank you very much !!!!!!!
I know your meaning .
I changed '+' to 'or' and got AC .
Thanks again !!!!